Hi all I wrote an article about applying Haskell's...
# library-development
d
Hi all I wrote an article about applying Haskell's Applicative Functor pattern to Kotlin coroutines fr parallel orchestration. The idea:
.ap
= parallel (
<*>
),
.flatMap
= sequential (
>>=
), the code shape is the execution plan. Includes side-by-side comparisons with raw coroutines and Arrow, JMH benchmarks. Article: https://dev.to/damian_lattenero/i-applied-haskells-applicative-functors-to-kotlin-coroutines-heres-what-happened-l06 GitHub: https://github.com/damian-rafael-lattenero/coroutines-applicatives Would love feedback on the API shape especially from anyone who's used Haskell's Applicative in other contexts.
e
in Haskell
<*>
isn't necessarily "parallel"; it's still sequential in IO
I think a more natural Kotlin API would be more like
Copy code
val ctx = awaitAllAndTransform(
    async { fetchProfile(userId) },
    async { fetchPreferences(userId) },
    async { fetchTier(userId) },
) { profile, preferences, tier ->
    UserContext(profile, preferences, tier)
}
d
yes thank you I updated it with that idea
s
Arrow-kt calls that
parZip
.
Copy code
val ctx = parZip(
    { fetchProfile(userId) },
    { fetchPreferences(userId) },
    { fetchTier(userId) },
) { profile, preferences, tier ->
    UserContext(profile, preferences, tier)
}