Skip to content

KotlinzFunctional programming for Kotlin

HKT-encoded type classes, data types, and category-theory constructs, with no dependencies.

Kotlinz

Install ​

Kotlinz is published on JitPack:

kotlin
repositories {
    mavenCentral()
    maven("https://jitpack.io")
}

dependencies {
    implementation("com.github.kotlinz:kotlinz:$version")
}

A taste of Kotlinz ​

Data types come with familiar infix operators, and fx gives you do-notation for any monad:

kotlin
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.

Released under the Apache License 2.0.