-
Notifications
You must be signed in to change notification settings - Fork 451
/
Copy pathat.kt
37 lines (33 loc) · 1.49 KB
/
at.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package arrow.optics.dsl
import arrow.optics.Lens
import arrow.optics.Optional
import arrow.optics.Prism
import arrow.optics.Traversal
import arrow.optics.typeclasses.At
/**
* 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 <T, S, I, A> Lens<T, S>.at(at: At<S, I, A>, i: I): Lens<T, A> = 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 <T, S, I, A> Optional<T, S>.at(at: At<S, I, A>, i: I): Optional<T, A> = 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 <T, S, I, A> Traversal<T, S>.at(at: At<S, I, A>, i: I): Traversal<T, A> = this.compose(at.at(i))