
org.http4k.lens.extractInject.kt Maven / Gradle / Ivy
package org.http4k.lens
interface LensInjector {
/**
* Lens operation to set the value into the target
*/
operator fun invoke(value: IN, target: R): R
/**
* Lens operation to set the value into the target. Synomym for invoke(IN, OUT)
*/
fun inject(value: IN, target: R): R = invoke(value, target)
/**
* Lens operation to set the value into the target. Synomym for invoke(IN, OUT)
*/
operator fun set(target: R, value: IN) = inject(value, target)
/**
* Bind this Lens to a value, so we can set it into a target
*/
infix fun of(value: IN): (R) -> R = { invoke(value, it) }
/**
* Restrict the type that this Lens can inject into
*/
fun restrictInto(): LensInjector = this
}
interface LensExtractor : (IN) -> OUT {
/**
* Lens operation to get the value from the target
* @throws LensFailure if the value could not be retrieved from the target (missing/invalid etc)
*/
@Throws(LensFailure::class)
override operator fun invoke(target: IN): OUT
/**
* Lens operation to get the value from the target. Synonym for invoke(IN)
* @throws LensFailure if the value could not be retrieved from the target (missing/invalid etc)
*/
@Throws(LensFailure::class)
fun extract(target: IN): OUT = invoke(target)
/**
* Lens operation to get the value from the target. Synonym for invoke(IN)
*/
operator fun get(target: R) = extract(target)
/**
* Restrict the type that this Lens can extract from
*/
fun restrictFrom(): LensExtractor = this
}
interface LensInjectorExtractor : LensExtractor, LensInjector
© 2015 - 2025 Weber Informatics LLC | Privacy Policy