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

It can be constructed by providing the Prism.

import arrow.optics.typeclasses.Snoc

val listLast = Snoc.list<Int>().snoc()
val instance = Snoc(listLast)

It defines two functions snoc and unsnoc.

snoc appends an element A to a structure S.

import arrow.optics.snoc

listOf(1, 2) snoc 3

unsnoc detaches the last element A from a structure S.

import arrow.optics.unsnoc

listOf(1, 2, 3).unsnoc()

Do you like Arrow?

Arrow Org