List("a"->1, "b"->2) match { case List( k->v ,_*) => println(k) }
error: not found: value ->List("a"->1, "b"->2) match { case List( (k,v) ,_*) => println(k) }
successMap("a"->1, "b"->2) match { case Map( (k,v) ,_*) => println(k) }
error: value Map is not a case class, nor does it have an unapply/unapplySeq member
Could you explain why that the left hand side succeeds using arrow ->
; while at right hand side the ->
failed.
If I change it to real type Tuple
(k,v), then it success.
However, failed again if using Map
.
I cannot image Scala didn't implement unapply
for Map?!
EDIT:
what I thought is ::
can be use in pattern matching; so could ->
.
OK , now ->
is a method , so cannot be matched.
Scala is not intuitive.