https://kotlinlang.org logo
#arrow
Title
# arrow
t

Tom Davis

11/15/2023, 10:11 PM
what's the most efficient path from
Either<Either<L, R>, R>
to
Either<L, R>
?
a

Alejandro Serrano.Mena

11/16/2023, 8:18 AM
the most efficient would definitelye be some sort of
when
Copy code
when {
  x is Either.Right -> x
  x is Either.Left -> x.value
}
you could also do
x.recover { it.bind() }
☝️ 2
ł

Łukasz Gendek

11/16/2023, 1:44 PM
x.flatten()
but I can see that flatten is not the inline method, so probably it is not as efficient as recover
s

simon.vergauwen

11/16/2023, 4:01 PM
flatten
, is only for right side so
Either<L, Either<L, R>>
but there could of course also be
flattenLeft()
but it's a very uncommon operator afaik.
ł

Łukasz Gendek

11/16/2023, 5:36 PM
Now I see
t

Tom Davis

11/16/2023, 7:04 PM
thanks, very helpful! 🙏
2 Views