You can translate the Haskell version directly to Scala if you want to be a little more verbose:
import scalaz._, Scalaz._ val a = Option(1) val b = Option(2) val f: Int => Int => Int = x => math.max(x, _) val c = b <*> (a map f)
Or, as a single line:
val c = 2.some <*> 1.some.map(x => math.max(x, _: Int))
Or:
val c = 2.some <*> (1.some map (math.max _).curried)
The order is reversed, because these are method calls instead of infix operators, but essentially this is the same as max <$> a <*> b : we map the function to the first element, and then apply the result to the second.
Travis brown
source share