With `Option` `map2`, one provides a lambda that h...
# arrow
j
With
Option
map2
, one provides a lambda that handles the case where both values are
Some
. But what if one wants to provide a lambda for all four possible cases? I can do this from scratch. But I wondered if there's a higher order function in Arrow that's already designed for this.
r
Hi Julian, check out Ior to see if it fits your use case better than Option https://arrow-kt.io/docs/0.10/apidocs/arrow-core-data/arrow.core/-ior/
👍🏾 1
d
j
You could use
Ior.fromOptions(optA, optB).fold(...)
which gives you an
Option<Ior<A, B>>
which should cover all cases. Alternatively we have a pr by @pablisco (who might be interested in this use-case) for a datatype just like the one @Danilo Herrera has in his gist, which can do this in just two steps (convert + fold instead of convert + fold + fold for the Ior one). The pr is here for those interested: https://github.com/arrow-kt/arrow-incubator/pull/109
👍🏾 3
👀 1
j
Awesome. Thanks @raulraja @Danilo Herrera @Jannis!
👍 2