Is there a `filterOrElse` equivalent for BIO? Curr...
# arrow
g
Is there a
filterOrElse
equivalent for BIO? Currently I had to write like this to set BIO to left of right state based on a boolean result (which feels boilerplate)
Copy code
val example: (IO<String, Int>) -> IO<String, Any?> =
                { valueIO ->
                    valueIO.map(::someBooleanResult)
                            .flatMap { if (it) IO.just(it) else IO.raiseError("error") }
                }
s
No, there is no
filterOrElse
available in BIO. I’m not sure if you missed it but, we’re going to revert BIO since we came up with a better and more powerful encoding! This will also completely solve your problem of effectful validation. https://github.com/arrow-kt/arrow-fx/pull/169
g
Oh! thanks @simon.vergauwen, I briefly grazed through it! Also waiting for ur Kotliners talk to learn more about it. Hope you will keep us posted when it is online! Thanks for this significant enhancement!
❤️ 2
arrow 2
s
I definitely will. I expect it to be published very soon!
@Gopal S Akshintala

https://www.youtube.com/watch?v=6sw8GAhUJz0

😉
👏 1
g
Thank you 😊
s
There is
Either.catch
which is like
attempt
but for
suspend
. If you want to
flattenEither
it's safe to simply
throw
inside
suspend
, which would be the same as attempting and flattening. Beside that
Either
has the same
MonadError
API as
IO
for recovering errors.
👍 2