All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.arrow.optics.dsl.at.kt Maven / Gradle / Ivy

The newest version!
package arrow.optics.dsl

import arrow.core.Option
import arrow.optics.Lens
import arrow.optics.Optional
import arrow.optics.Prism
import arrow.optics.Traversal
import arrow.optics.typeclasses.At
import kotlin.jvm.JvmName

/**
 * DSL to compose [At] with a [Lens] for a structure [S] to focus in on [A] at given index [I].
 *
 * @receiver [Lens] with a focus in [S]
 * @param at [At] instance to provide a [Lens] to zoom into [S] at [I]
 * @param i index [I] to zoom into [S] and find focus [A]
 * @return [Lens] with a focus in [A] at given index [I].
 */
public fun  Lens.at(at: At, i: I): Lens = this.compose(at.at(i))

/**
 * DSL to compose [At] with an [Optional] for a structure [S] to focus in on [A] at given index [I].
 *
 * @receiver [Optional] or [Prism] with a focus in [S]
 * @param at [At] instance to provide a [Lens] to zoom into [S] at [I]
 * @param i index [I] to zoom into [S] and find focus [A]
 * @return [Optional] with a focus in [A] at given index [I].
 */
public fun  Optional.at(at: At, i: I): Optional = this.compose(at.at(i))

/**
 * DSL to compose [At] with a [Traversal] for a structure [S] to focus in on [A] at given index [I].
 *
 * @receiver [Traversal] with a focus in [S]
 * @param at [At] instance to provide a [Lens] to zoom into [S] at [I]
 * @param i index [I] to zoom into [S] and find focus [A]
 * @return [Traversal] with a focus in [A] at given index [I].
 */
public fun  Traversal.at(at: At, i: I): Traversal = this.compose(at.at(i))

public fun  Lens>.at(key: K): Lens> =
  this.compose(At.map().at(key))

public fun  Optional>.at(key: K): Optional> =
  this.compose(At.map().at(key))

public fun  Traversal>.at(key: K): Traversal> =
  this.compose(At.map().at(key))

@JvmName("atSet")
public fun  Lens>.at(value: A): Lens =
  this.compose(At.set().at(value))

@JvmName("atSet")
public fun  Optional>.at(value: A): Optional =
  this.compose(At.set().at(value))

@JvmName("atSet")
public fun  Traversal>.at(value: A): Traversal =
  this.compose(At.set().at(value))





© 2015 - 2025 Weber Informatics LLC | Privacy Policy