8
votes

I was reading through some examples of Akka, specifically the ChatServer example by Jonas Boner, and I came across case msg @ GetChatLog =>. I've tried to figure out what the @ symbol means by searching in akka documentation and various articles about pattern matching in scala with no luck. Does anyone have an idea of what it means?

1
It's called variable binding. - Ende Neu
In general, scala symbols are documented here docs.scala-lang.org/tutorials/FAQ/finding-symbols.html - 1565986223

1 Answers

11
votes

@ binds the object being pattern matched to a variable. msg @ GetCharLog will result in msg holding a reference to the GetCharLog object, which isn't very useful. A better example is msg @ Foo(a, b, c), which will result in msg holding a reference to the instance of Foo that is matched on, which lets you forward the received message (for example) without needing to construct another instance of Foo with a, b, and c.