Having
(Some(1), Some(2))
I expect to get
Some((1, 2))
and having
(Some(1), None)
Starting Scala 2.13
, this exact behavior is provided in the standard library by Option#zip:
Some(2) zip Some('b') // Some((2, 'b'))
Some(2) zip None // None
None zip Some('b') // None
None zip None // None
Before Scala 2.13
, Option#zip was returning an Iterable
and it was possible to combine it with headOption
:
Some(2) zip Some('b') headOption // Some((2, 'b'))
Some(2) zip None headOption // None