A simple, lightweight IO monad implementation for Kotlin inspired to the effect-rotation based ZIO library for Scala.
Introducing KIO: https://www.msec.it/blog/introducing-kio/
Comprehension-like syntax: https://www.msec.it/blog/comprehension-like-syntax-in-kotlin/
Many functional programming languages (like Clojure and F#), even if they could (more or less) support the Haskell typeclasses-like FP approach, doesn’t rely on it in order to provide a functional programming environment. Instead, they just rely on the most important pillars of functional programming that are referential transparency and immutability, usually complemented with the use of algebraic data types (ADTs).
Kotlin already provides many tools that can help the developers to stick with these principles, like data classes,
sealed classes and immutable variables (
The two most notable missing pieces are a way to easily handle referential transparency
when side effects are involved and an error handling alternative to exceptions.
KIO is a lightweight IO implementation that tries to fill this gap without aspiring to provide all the classic
Haskell/Scala typeclass categories. If you are looking for this type of library,
take a look at Arrow instead.
KIO provides a IO monad-like implementation specific for Kotlin with the following features:
- Small and lightweight;
- Everything is lazy (deferred);
- Support for typed errors (like the Either construct);
- Support for exception handling (like the Try construct);
- Support for optional values (like the Option construct);
- Support for injecting an environment (data or functions) to the program (like the ReaderT construct);
- Support for asynchronous and parallel processing via native coroutines integration;
- Support for atomic, concurrent and mutable references.
Also some utility methods are available for lists and null-handling.
<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories> <dependencies> <dependency> <groupId>it.msec.KIO</groupId> <artifactId>kio</artifactId> <version>0.5</version> </dependency> </dependencies>
You can find some documentation in order to start with KIO here.