Skip to content
Lenses for Kotlin
Branch: master
Clone or download
Dominic Fox
Dominic Fox Correct README
Latest commit 05fcece May 9, 2016
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Implicit conversions, edge cases May 9, 2016
.gitignore gitignore May 7, 2016
.travis.yml travis May 7, 2016
LICENSE Initial commit May 7, 2016 Correct README May 9, 2016


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() })
You can’t perform that action at this time.