arrow-optics / arrow.optics.typeclasses / Cons

Cons

interface Cons<S, A>

Cons provides a Prism between S and its first element A and tail S. It provides a convenient way to attach or detach elements to the left side of a structure S.

Parameters

S - source of Prism and tail of Prism focus.

A - first element of Prism focus, A is supposed to be unique for a given S.

Functions

cons abstract fun cons(): Prism<S, Tuple2<A, S>>
Provides a Prism between S and its first element A and tail S.open infix fun A.cons(tail: S): S
Prepend an element A to the first element of S.
firstOption open fun firstOption(): Optional<S, A>
Provides an Optional between S and its first element A.
tailOption open fun tailOption(): Optional<S, S>
Provides an Optional between S and its tail S.
uncons open fun S.uncons(): Option<Tuple2<A, S>>
Deconstruct an S to its optional first element A and tail S.

Companion Object Functions

fromIso fun <S, A, B> fromIso(C: Cons<A, B>, iso: Iso<S, A>): Cons<S, B>
Lift an instance of Cons using an Iso.
invoke operator fun <S, A> invoke(prism: Prism<S, Tuple2<A, S>>): Cons<S, A>

Inheritors

ListCons interface ListCons<A> : Cons<List<A>, A>
Cons instance definition for List.
ListKCons interface ListKCons<A> : Cons<ListK<A>, A>
Cons instance definition for ListK.
StringCons interface StringCons : Cons<String, Char>

Type Class Hierarchy