Lens

interface Lens<P, T>

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

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

Properties

Link copied to clipboard
abstract val id: String

identifies the focus of this lens

Extensions

Link copied to clipboard
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, Short>.asString(): Lens<P, String>
fun <P> Lens<P, Short?>.asString(emptyValue: String = ""): Lens<P, String>

Creates a Lens from Short 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, 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, Boolean?>.asString(emptyValue: String = ""): Lens<P, String>

Creates a Lens from Boolean to String

fun <P> Lens<P, List<Byte>>.asString(separator: String = ", ", prefix: String = "", postfix: String = ""): Lens<P, String>

Creates a Lens from List of Byte to String

fun <P> Lens<P, List<Short>>.asString(separator: String = ", ", prefix: String = "", postfix: String = ""): Lens<P, String>

Creates a Lens from List of Short to String

fun <P> Lens<P, List<Int>>.asString(separator: String = ", ", prefix: String = "", postfix: String = ""): Lens<P, String>

Creates a Lens from List of Int to String

fun <P> Lens<P, List<Long>>.asString(separator: String = ", ", prefix: String = "", postfix: String = ""): Lens<P, String>

Creates a Lens from List of Long to String

fun <P> Lens<P, List<Double>>.asString(separator: String = ", ", prefix: String = "", postfix: String = ""): Lens<P, String>

Creates a Lens from List of Double to String

fun <P> Lens<P, List<Float>>.asString(separator: String = ", ", prefix: String = "", postfix: String = ""): Lens<P, String>

Creates a Lens from List of Float to String

fun <P> Lens<P, List<String>>.asString(separator: String = ", ", prefix: String = "", postfix: String = ""): Lens<P, String>

Creates a Lens from List of String to String

Link copied to clipboard
fun <P, T> Lens<P, T>.toNullableLens(): 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.