I've been looking at someone's code and noticed this
case overdue @ PendingOperation(operation, _) => ......
What does @ symbol mean here? How is it called?
It's called variable binding.
It binds the value being matched on to the overdue
variable.
In this way you can both destructure the value by pattern matching over it and later reference it as a whole.
While it's not particularly useful in a case like
foo match {
case a @ Bar(baz, bar) => ...
}
since you can directly refer to foo
, it gets more interesting in cases like
foo match {
case Bar(b @ Baz("hello", _), _) => ...
}
where you bind an inner match to a variable.