Scala 2 Symbols

Views
Article hero image

Symbols

Symbol Description
<- Used on for-comprehensions, to separate pattern from generator
=> Used for function types, function literals and import renaming

Reserved

Symbol Description
// /* */ Comments
" """ Strings
$ String interpolation
' Indicate symbols and characters
, Parameter separator
; Statement separator
( ) Delimit expressions and parameters
[ ] Delimit type parameters
{ } Delimit blocks, pattern matching lambda blocks
. Method call and path separator
# Used in type notations
: Type ascription or context bounds
<: >: Upper and lower bounds
<% View bounds (deprecated)
@ Annotations and variable binding on pattern matching
backtick Denote constant or enable arbitrary identifiers
_* Vararg expansion
_. Many different meanings
-> Map/tuple

Underscore

Symbol Description
import scala._ Wild card – all of Scala is imported
import scala.{ Predef => _, _ } Exclusion, everything except Predef
case _ => Wild card pattern – matches anything
def f[M[_]] Higher kinded type parameter
def f(m: M[_]) Existential type
m _ Eta expansion of method into method value
m(_) Partial function application
_ + _ Anonymous function placeholder parameter
_ => 5 Discarded parameter
f(xs: _*) Sequence xs is passed as multiple parameters to f(ys: T*)
case Seq(xs @ _*) Identifier xs is bound to the whole matched sequence
scala symbols