is it possible to provide async versions of `.map`...
# arrow
p
is it possible to provide async versions of
.map
/
.flatMap
from arrow? right now it seems i will have to write extension functions that do something similar
This is what an extension function looks like:
Copy code
suspend fun <A, B, C> Either<A, B>.flatMapAsync(fn: suspend (B) -> Either<A, C>): Either<A, C> {
    return when (this) {
        is Either.Left -> this
        is Either.Right -> fn(this.b)
    }
}
c
Which version are you using?
in latest versions, it’s an inline function, allowing you to make asynchronous calls
☝️ 1
s
All
inline
functions allow for
suspend
from inside the lambda, and Arrow Fx Coroutines contains some more utilities if you’re looking for parallel operators such as
parZip
,
race
or
parTraverse
, etc
p
i’m on 0.11.0
s
Oh, that’s a rather old version. Any reason you use
0.11.0
?
p
might be challenging to upgrade to kotlin 1.5
(other dependencies we need to wait for). i’m not sure if those libraries are backwards compat? perhaps — i hope it’s better than scala 😅
s
Oh okay. Ye, that can be a pickle 😅
This is the new approach Arrow takes for this issue instead of declaring it as
flatMapAsync
. https://github.com/arrow-kt/arrow/blob/main/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt#L1103
The suspending either DSL could be back-ported to
0.11.0
p
neat! i will look at what it’d take to upgrade — do you know what version this was introduced in?
s
This was introduced in
0.12.0
, which should be compatible with
0.11.0
. You can try bumping to
0.12.1
and then you should have this available
👍 1
If you cannot upgrade, I can help you backport the
either { }
DSL so you can use it instead of
flatMap
(& co) for suspending code.