Lens

interface Lens<P, T>

Describes a focus point into a data structure, i.e. a property of a given complex entity

Properties

Link copied to clipboard
abstract val id: String

identifies the focus of this lens

Functions

Link copied to clipboard
open suspend fun apply(parent: P, mapper: suspend (T) -> T): P

manipulates the focus target's value inside the parent

Link copied to clipboard
fun <P> Lens<P, Boolean?>.asString(emptyValue: String = ""): Lens<P, String>

Creates a Lens from Boolean to String

fun <P> Lens<P, Byte>.asString(): Lens<P, String>
fun <P> Lens<P, Byte?>.asString(emptyValue: String = ""): Lens<P, String>

Creates a Lens from Byte to String

fun <P> Lens<P, Double?>.asString(emptyValue: String = ""): Lens<P, String>

Creates a Lens from Double to String

fun <P> Lens<P, Float>.asString(): Lens<P, String>
fun <P> Lens<P, Float?>.asString(emptyValue: String = ""): Lens<P, String>

Creates a Lens from Float to String

fun <P> Lens<P, Int>.asString(): Lens<P, String>
fun <P> Lens<P, Int?>.asString(emptyValue: String = ""): Lens<P, String>

Creates a Lens from Int to String

fun <P> Lens<P, Long>.asString(): Lens<P, String>
fun <P> Lens<P, Long?>.asString(emptyValue: String = ""): Lens<P, String>

Creates a Lens from Long to String

fun <P> Lens<P, Short>.asString(): Lens<P, String>
fun <P> Lens<P, Short?>.asString(emptyValue: String = ""): Lens<P, String>

Creates a Lens from Short to String

Link copied to clipboard
abstract fun get(parent: P): T

gets the value of the focus target

Link copied to clipboard
open operator fun <X> plus(other: Lens<T, X>): Lens<P, X>

appends to Lenses so that the resulting Lens points from the parent of the Lens this is called on to the target of other

Link copied to clipboard
abstract fun set(parent: P, value: T): P

sets the value of the focus target

Link copied to clipboard
open fun withNullParent(): Lens<P?, T>

For a lens on a non-nullable parent this method creates a lens that can be used on a nullable-parent Use this method only if you made sure, that it is never called on a null parent. Otherwise, a NullPointerException is thrown.