A lightweight Kotlin Multiplatform library providing functional programming extensions and utilities for nullable handling, type casting, flow lifting, and more.
Targets: Android · iOS · JVM
- Suspended
letCofor coroutine-friendly mapping orDefaultandorDefaultCofor safe null defaultsonNullandonNullCofor executing side-effects on null- Reified casts:
asType,asTypeOrNull - Null-aware
match,matchCo,matchAction,matchCoAction liftfunctions for combining up to three nullable values- Fully documented with KDoc and usage examples
dependencies {
implementation("io.github.ktomek:funKtional:1.2.0")
}// letCo example
runBlocking {
val length = "Hello".letCo { it.length }
println(length) // 5
}
// orDefault example
val value: String? = null
val default = value.orDefault { "default" }
println(default) // "default"
// asType / asTypeOrNull example
val any: Any = "text"
val text: String? = any.asTypeOrNull<String>()
println(text) // "text"
// lift example
val sum: Int? = 2.lift(3) { a, b -> a + b }
println(sum) // 5runBlocking {
val x: Int? = null
val y: Int? = 5
val z: Int? = 10
// Combine nullable values, provide default, then transform
val result = x.lift(y, z) { a, b, c -> a + b + c }
.orDefault { 0 }
.letCo { it * 2 }
println(result) // (0 + 5 + 10) * 2 = 30
}
// Null-safe branching with match
val branch = "Kotlin"
.match(
some = { it.length },
none = { 0 }
)
.let { length -> "Length is $length" }
.also { println(it) } // "Length is 6"Contributions are welcome! Please open issues or submit pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.