hello, everyone is there a shorter/cleaner way to ...
# arrow
d
hello, everyone is there a shorter/cleaner way to do the following
Copy code
either1.fold(
        ifLeft = { it.left() },
        ifRight = { r1 ->
            either2.fold(
                    ifLeft = { it.left() },
                    ifRight = { r2 -> mapper(r1, r2).right() },
            )
        }
)
The left type of both eithers is the same. I want to call mapper() if both of eithers are
Right
. If one of them is
Left
, mapper won't be called. The result type is
Either<SameLeftType, ReturnedTypeFromMapper>
.
t
Copy code
Either.mapN(e1, e2){ a, b -> mapper(a,b) }
d
thanks @than_! Which version is this included in? I'm using Arrow-Core 0.11 and it's not there
t
sorry. this moved in 0.12.0-SNAPSHOT.. I believe it's just
Copy code
mapN(e1, e2){ a, b -> mapper(a,b) }
in 0.11.0
d
ah, right! Thanks
t
Copy code
import arrow.core.extensions.either.apply.mapN
I believe it can be found here
d
However this doesn't look like what I need. It's for nullable types, not Either or am I wrong?
t
wrong import 🙂
d
🙈 thanks
t
there is A LOT of mapN functions. I believe there is one for every monad (and nullables), for every arity up to like 10 😄 Just search a bit
d
Yeah, I guess they moved it to Either. for a reason 😄