tur/list
stdlib/list.tur
defstruct
Cons
(defstruct Cons [value :int next :int])
defn
nil-value
(nil-value)
return the empty list sentinel (NULL / 0).
Since: Phase B1
defn
list-nil?
(list-nil? [lst] :bool)
check whether a list is empty.
Parameters
| lst | the list to test |
Since: Phase B1
defn
cons
(cons [value next] :int)
prepend a value to a list, returning a new Cons cell.
Parameters
| value | the element to prepend | |
| next | the existing list (or nil-value for a one-element list) |
Since: Phase B1
defn
head
(head [lst] :int)
return the value of the first element of a list.
Parameters
| lst | a non-nil list |
Since: Phase B1
defn
tail
(tail [lst] :int)
return the rest of the list after the first element.
Parameters
| lst | a non-nil list |
Since: Phase B1
defn
list-free
(list-free [lst])
free all Cons cells in a list (shallow -- does not free contained values).
Parameters
| lst | the list to free (may be nil-value) |
Since: Phase B1
defn
list-length
(list-length [lst] :int)
return the number of elements in a list.
Parameters
| lst | the list to measure |
Since: Phase B1
definstance
Clone[Cons]
(definstance Clone [Cons])
shallow Clone for a single Cons cell.
definstance
Functor[list]
(definstance Functor [list])
Functor: fmap over every element.
definstance
Foldable[list]
(definstance Foldable [list])
Foldable: foldl and foldr over all elements.
definstance
Applicative[list]
(definstance Applicative [list])
Applicative: pure and ap.
definstance
Monad[list]
(definstance Monad [list])
Monad: bind (concat-map).
defn
list-eq?
(list-eq? [l1 l2 cmp-fn] :bool)
compare two lists element-wise using a caller-supplied comparator.
Parameters
| l1 | first list | |
| l2 | second list | |
| cmp-fn | comparator of type fn [a :int b :int] :bool |
Since: Phase E1
definstance
Eq[list]
(definstance Eq [list])
Eq: structural equality via list-eq?.
Internal definitions
__functor_list_fmap-- SINCE: Phase HKT §6 — Stdlib HKT migration__foldable_list_foldl-- foldl implementation for the list Foldable instance.__foldable_list_foldr-- foldr implementation for the list Foldable instance.__applicative_list_pure-- pure implementation for the list Applicative instance.__applicative_list_ap-- ap implementation for the list Applicative instance.__monad_list_bind-- bind implementation for the list Monad instance.