Oh okay, you want `leftFlatMap` but that currently...
# arrow
s
Oh okay, you want
leftFlatMap
but that currently doesn’t exist in Arrow.
r
If it’s still ok to add
flatMapLeft
I did create a branch with the functionality + test. I get an error pushing my branch up to origin because of permissions. No big deal if you’d prefer not to add extra code to maintain @simon.vergauwen @pakoito. Up to you guys.
p
I';d rather not, we aligned the names not so long ago
and we moved from mapLeft to handleError for example
s
But this is different from
handleErrorWith
It doesn’t fix
L
but rather leaves it generic.
It’s an operator of the bifunctor hierarchy, right?
r
Cool,
handleErrorWith
does work perfectly for my use case so I can stick with that. Thanks for pointing me in the right direction!
p
flatMapLeft
is a specialized
handleErrorWith
or just a plain alias
s
It’s the other way around
p
because you can return handleErrorWith { Either.Left("") }
I thought we kept the handleError naming so it was consistent across datatypes
s
Copy code
fun <A, B, C> Either<A, B>.leftFlatmap(f: (A) -> Either<C, B>): Either<C, B> = when(this) {
  is Either.Left -> f(this.a)
  is Either.Right -> this
}

fun <A, B> Either<A, B>.handleErrorWith(f: (A) -> Either<A, B>): Either<A, B> = leftFlatMap(f)
I’m not favoring one over the other. I’d include both since I expect
leftFlatMap
to come back when we complete the bifunctor hiearchy.
It’s a very handy operator for
IO<E, A>
over
handleErrorWith
Because it can to change
E
to
Nothing
, well I guess you could name it
handleErrorWith
in a bifunctor hierarchy but then it would be an alias. Here it’s not.
@Robert Menke you’re very welcome! Glad to help any time. Sorry for the confusion.
❤️ 1
r
So 1 other consideration is that
handleErrorWith
is not an
inline
function so it actually doesn’t work for my use case because I need to call
suspend
functions inside. I can get by with
fold
for now, just voicing my experience.
s
That is where
IO
comes in,
Either
cannot deal with the powers of
suspend
. It cannot control the async jumps, exception being thrown etc.
r
Gotcha 👍 so just out of curiosity (and ignorance) why inline certain functions like
flatMap
or
fold
but not something like
handleErrorWith
?
s
With
IO
you'd do
io.handleErrorWith { e -> IO.effect { suspendFunction() } }
If those functions are still inline then that will probably change soon.
r
Ok that makes sense! Thanks!