give pattern-matched anonymous function:
val = list((1,2), (3,4)) val c = a.map{case (x, y) => (y, x)}
is there way achieve same thing function literal using similar syntax?
val f = case (x,y) => (y,x) val c = a.map(f)
something better this:
val f = (z: (int, int)) => { z match { case (x, y) => (y, x) } }
it works if type annotate , surround in {}:
scala> val f: (int,int) => (int,int) = { case (x, y) => (y,x) } f: (int, int) => (int, int) = <function2>
Comments
Post a Comment