scalafunctorscalazscalaz7

What's the new name for map2 in Scalaz 7?


Jordan West in this presentation from Scalamachine clearly speaks about map2 function. Turns out the function was available in Scalaz 6 but I can't find it or any equivalent in Scalaz 7.

E.g. I would like to be able to run this code:

List(Some(1), Some(2)).map2(_ + 1)

and get as a result

List(Some(2), Some(3))

Where can I find this function in Scalaz 7?

EDIT: Ideally, I would like to be able to execute any function f: A => B on l: List[Option[A]]

l.map2(f)

And get List[Option[B]] with the intuitive semantics.


Solution

  • Ok, there does not seem to exist such function in Scalaz 7 but there is a nice way around using Monad Transformers:

    OptionT[List, Int](List(Some(1), Some(2))).map(_ + 1).run
    
    // List(Some(2), Some(3))
    

    or in the case of l: List[Option[A]]

    OptionT[List, A](l).map(f).run