Filip Piechowski
02/23/2024, 10:50 AMsimon.vergauwen
02/23/2024, 11:09 AMFunctor
, Applicative
, Monad
, etc. We've found that working with suspend
, and context based DSLs works much nicer.
For example: Kleisli[EitherT[IO, E, ?], R, A]
can be replaced with
context(_: Raise<E>)
suspend R.function(): A = TODO()
So we don't need monad transformers, or flatMap
to compose these behaviors. Instead we can still rely on simple function composition.
This is very in spirit with nullable types, A?
vs Option<A>
and the already mentioned suspend
vs IO
. While this doesn't cover 100% of the use-cases, we feel it covers 99% of them and so far every problem we've encountered we've always were able to encode it as a context. Other examples are: SagaScope
, ResourceScope
, AutoCloseScope
, and FlowCollector
, ProducerScope
, etc are also other great example from KotlinX Coroutines.
While it might be possible in the future to achieve with compiler plugins, I'm afraid it wouldn't fit nicely into the Kotlin ecosystem.simon.vergauwen
02/23/2024, 11:09 AMFilip Piechowski
02/23/2024, 11:13 AMraulraja
02/23/2024, 12:02 PM