Cons

beginner

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.data.ListK
import arrow.optics.instances.listk.cons.cons
import arrow.optics.typeclasses.Cons

val listFirst = ListK.cons<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.instances.list.cons.cons

1.cons(listOf(2, 3))

uncons detaches the first element A from a structure S.

import arrow.optics.instances.list.cons.uncons

listOf(1, 2, 3).uncons()
emptyList<Int>().uncons()

Data types

import arrow.reflect.*
import arrow.optics.typeclasses.*

TypeClass(Cons::class).dtMarkdownList()