Hey, is there something like `switchMap` in Arrow ...
# arrow
r
Hey, is there something like
switchMap
in Arrow that can be used for scenarios like this:
Copy code
Option
    .fromNullable(someValue)
    .map { /* calls a function that returns Either<Error, Value> */}
After calling map I have
Option<Either<Error, Value>>
wondering if there’s any way to avoid the extra wrapping. CC @Derek Seroky
k
Copy code
Option.fromNullable(someValue)
            .map { /* calls a function*/ }
            .toEither { Error.AbsentValue }
or
Copy code
Either.cond(someValue != null, { Error.AbsentValue }, { callTheFunction(someValue) })
i
@Robert Menke If you think about it this type
Copy code
Option<Either<Error, Value>>
is isomorphic aka ‘equal’ to
Copy code
Either<Nothing, Either<Error, Value>>
If there is a chance to flatten this stack, I recommend you to do it. You may have to see that
Option<A>
is isomorphic to
Either<Nothing, A>
It’s similar to the problem one faces with overly nested types. They’re hard to dig into, you’ll have to do a lot of fmap’s, unless you use arrow-optics and the library does that for you. If you’re carious about a plausible reality. I recommend watching this for a few minutes to get the idea

https://youtu.be/VOZZTSuDMFE?t=389

r
Awesome, thank you for the link. I ended up taking everyone’s advice and just sticking to
Either
in this case. Works great and is much simpler!
💪🏽 1