klenses - Lenses for Kotlin - Kotlin Resources


Lenses for Kotlin.

Maven Central Build Status

Lenses are property references with some extra abilities: they can also be used to create a copy of an object with the property set to a different value, and they compose to form pointers into nested objects.

data class Inner(val value: String)
data class Outer(val outerValue: String, val inner: Inner?)

val foo = Outer("foo", null)

val outerValueLens = +Outer::outerValue
val innerLens = Outer::inner orElse Inner("xyzzy")
val innerValueLens = innerLens + Inner::value 

assertEquals("foo", outerValueLens(foo))
assertEquals(Outer("quux", null), outerValueLens(foo, "quux"))
assertEquals(Inner("xyzzy"), innerLens(foo))
assertEquals(Outer("foo", Inner("frobnitz")), innerValueLens(foo, "frobnitz"))
assertEquals(Outer("foo", Inner("XYZZY")), innerValueLens(foo) { toUpperCase() })
compile "com.codepoetics:klenses:0.4"

Related Libraries


Vavr integration for Kotlin

Last updated 3 mins ago


An observables framework for Kotlin

Last updated 3 mins ago


Kotlin extensions to the RxJavaFX framework

Last updated 3 mins ago


Fluent RxJava JDBC extension functions for Kotlin

Last updated 3 mins ago


RxJava bindings for Kotlin

Last updated 3 mins ago