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
Discussion
Get the discussion rolling
A single comment can start something great.