arrow-optics / arrow.optics.typeclasses / Snoc

Snoc

interface Snoc<S, A>

Snoc defines a Prism between a S and its init and last element A and thus can be seen as the reverse of Cons. It provides a way to attach or detach elements on the end side of a structure.

Parameters

S - source of Prism and init of Prism target.

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

Properties

init open val S.init: Option<S>
Selects all elements except the last.

Functions

initOption open fun initOption(): Optional<S, S>
Provides an Optional between S and its init S.
lastOption open fun lastOption(): Optional<S, A>
Provides an Optional between S and its last element A.
snoc abstract fun snoc(): Prism<S, Tuple2<S, A>>
Provides a Prism between a S and its init and last element A.open infix fun S.snoc(last: A): S
Append an element A to S.
unsnoc open fun S.unsnoc(): Option<Tuple2<S, A>>
Deconstruct an S between its init and last element.

Companion Object Functions

fromIso fun <S, A, B> fromIso(SS: Snoc<A, B>, iso: Iso<S, A>): Snoc<S, B>
Lift an instance of Snoc using an Iso.
invoke operator fun <S, A> invoke(prism: Prism<S, Tuple2<S, A>>): Snoc<S, A>
Construct a Snoc instance from a Prism.

Inheritors

ListKSnoc interface ListKSnoc<A> : Snoc<ListK<A>, A>
Snoc instance definition for ListK.
ListSnoc interface ListSnoc<A> : Snoc<List<A>, A>
Snoc instance definition for List.
StringSnoc interface StringSnoc : Snoc<String, Char>

Type Class Hierarchy