I have an `Either<E,V>`. I want to run some ...
# arrow
p
I have an
Either<E,V>
. I want to run some extra checks on
V
and end up with a
Left
if they fail. Is there a utility function?
Ex:
10.right().someFunc({ it.isOdd()}, { -> "Not Odd".left() })
, what can
someFunc
be?
I'm stupid, I can use Either.cond for this.
k
you can use
flatMap
as well in case you don’t have access to the Either construction.
Copy code
fun myFunction(e: Either<Exception, Int>) =
e.flatMap{
  Either.cond(it.isOdd(), { it }, { error })
}
👍 1