Type classes
Functor, Applicative, Selective, Monad, Traversable, Filterable, Align, MTL-style classes, Profunctor, Arrow and more, as ordinary interfaces over the lightweight K1 encoding.
Explore the hierarchy
HKT-encoded type classes, data types, and category-theory constructs, with no dependencies.
Kotlinz is published on JitPack:
repositories {
mavenCentral()
maven("https://jitpack.io")
}
dependencies {
implementation("com.github.kotlinz:kotlinz:$version")
}Data types come with familiar infix operators, and fx gives you do-notation for any monad:
import com.github.kotlinz.kotlinz.data.maybe.Maybe
fun parse(s: String): Maybe<Int> = s.toIntOrNull()?.let { Maybe.Just(it) } ?: Maybe.None()
val doubled = parse("21") fmap { it * 2 }
val sum = Maybe.fx {
val a = parse("1").bind()
val b = parse("2").bind()
a + b
}
check(doubled == Maybe.Just(42))
check(sum == Maybe.Just(3))
check(parse("x").getOrElse(0) == 0)Continue with Getting Started, or jump straight into the guides.