Reputation: 7445
Consider a function f : A -> Option[B]
.
I want to flatMap using f
, but keep the original value in the result as well, as a pair of values (A,B)
.
I can write it like this:
collection.flatMap(a => {
f(a) match {
case Some(b) => Some((a,b))
case None => None
}
})
But is there a nicer way?
Upvotes: 0
Views: 168