I have following code snippet:
def traverse[E, A, B](es: List[A])(f: A => Either[E, B]): Either[E, List[B]] =
es match {
case Nil => Right(Nil)
case h :: t => (f(h) map2 traverse(t)(f)) (_ :: _)
}
the map2 function implementation:
def map2[EE >: E, B, C](b: Either[EE, B])(f: (A, B) => C): Either[EE, C] =
for {
aa <- this
bb <- b
} yield (f(aa, bb))
What I do not understand is this code:
(f(h) map2 traverse(t)(f)) (_ :: _)
First, the function f will be apply to argument h. After it will call map2 function until it reached the Nil in List. What is the (_ :: _) function for? So weird function call.