what this scala symbol ->_ means -


can assist me understanding code

case "foo" foo(data) -> _ => { /*.. implementation */} 

i see usage of foo.unapply(data) don't understand part

-> _

how , when use

it looks being way clever own good. suppose i've got following:

case class foo[a](command: string, data: a)  object -> { def unapply[a, b](p: (a, b)) = some(p) } 

now can write this:

scala> foo("foo", (42, 'whatever)) match {      |   case "foo" foo(data) -> _ => data      | } res0: int = 42 

thanks magic of scala's infix patterns, equivalent following:

foo("foo", (42, 'whatever)) match {   case foo("foo", data -> _) => data } 

except infix version guaranteed confuse , annoy code's future readers.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -