Cons provides a Prism between a structure S and its first element A and tail S.
It provides a convenient way to attach or detach elements to the beginning side of a structure [S].
It can be constructed by providing the Prism.
import arrow.optics.typeclasses.Cons
val listFirst = Cons.list<Int>().cons()
val instance = Cons(listFirst)
instance
It defines two functions: cons and uncons.
cons prepends an element A to a structure S.
import arrow.optics.cons
1 cons listOf(2, 3)
uncons detaches the first element A from a structure S.
import arrow.optics.uncons
listOf(1, 2, 3).uncons()
emptyList<Int>().uncons()
Do you like Arrow?
✖