I want to do something like this List(1 -> 2, 4 -> 5).map(_ + _) to get List(3, 9) as a result. But it doesn’t work that way.
Does Scalaz provide means to deal with this in a convenient way, unlike the Scala’s native “tupled” or pattern matching?
I actually think the following is exceptionally convenient—even better than the pattern matching versions in the other answers:
But I’ll be perverse and provide a Scalaz solution to a slightly different problem. Suppose we’re working with streams instead of lists, and also suppose we built our stream of pairs by zipping the following two streams:
Scalaz includes an instance of what’s called the “zip list” applicative functor for streams. It’s not the default instance, but we can “tag” our streams appropriately and use it like this:
And there you go! A Scalaz solution to a vaguely related problem. (I’m only being a little sarcastic—I love this stuff, and the zip list applicative functor is worth knowing about.)