How currying, functors, applicative functors and monads from Haskell led me to build a parallel orchestration library for Kotlin coroutines with zero overhead.
tags: kotlin, functionalprogramming, haskell, coroutines
If you know Haskell, you already know this library
In Haskell, combining independent IO actions looks like this:
mkDashboard <$> fetchUser <*> fetchCart <*> fetchPromos
Three independent effects. The runtime can execute them however it wants — including in parallel. The structure tells you: these don't depend on each other.
When one result depends on another, you switch to monadic bind:
do
ctx <- mkContext <$> fetchProfile <*> fetchPrefs <*> fetchTier
mkDashboard <$> fetchRecs ctx <*> fetchPromos ctx <*> fetchTrending ctx
Phase 1 is applicative (parallel). Phase 2 is monadic (depends on ctx). The code shape is the dependency graph.
I looked at Kotlin coroutines and saw the same problem: you need to orchestrate parallel calls with sequential barriers, but async/await gives you no way to express this distinction. So I built — tracked on every push to master.
Getting started
Three modules, pick what you need:
dependencies {
// Core — the only required module (zero deps beyond coroutines)
implementation("io.github.damian-rafael-lattenero:kap-core:2.1.0")
// Optional: resilience (Schedule, CircuitBreaker, Resource, bracket)
implementation("io.github.damian-rafael-lattenero:kap-resilience:2.1.0")
// Optional: Arrow integration (validated DSL, Either/Nel, raceEither)
implementation("io.github.damian-rafael-lattenero:kap-arrow:2.1.0")
}
906 tests across 61 suites. 119 JMH benchmarks. Kotlin Multiplatform (JVM / JS / Native). 7 runnable examples. Algebraic laws (Functor, Applicative, Monad) property-tested with Kotest.
All code examples in this post are compilable — they live in
SOCIAL SHARE CARD GENERATOR