Robert Menke
06/06/2019, 7:19 PMswitchMap
in Arrow that can be used for scenarios like this:
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 Serokykioba
06/06/2019, 7:57 PMOption.fromNullable(someValue)
.map { /* calls a function*/ }
.toEither { Error.AbsentValue }
or
Either.cond(someValue != null, { Error.AbsentValue }, { callTheFunction(someValue) })
Imran/Malic
06/06/2019, 8:36 PMOption<Either<Error, Value>>
is isomorphic aka ‘equal’ to
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>
Imran/Malic
06/06/2019, 8:43 PMRobert Menke
06/06/2019, 9:19 PMEither
in this case. Works great and is much simpler!