mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 05:34:11 +03:00
35 lines
578 B
Plaintext
35 lines
578 B
Plaintext
interface ConsList exposes [ConsList, empty, isEmpty, map, len] imports []
|
|
|
|
ConsList a : [ Cons a (ConsList a), Nil ]
|
|
|
|
empty : ConsList a
|
|
empty = Nil
|
|
|
|
len : ConsList a -> Int *
|
|
len = \list ->
|
|
when list is
|
|
Cons _ rest -> 1 + len rest
|
|
|
|
Nil ->
|
|
0
|
|
|
|
|
|
map : ConsList a, (a -> b) -> ConsList b
|
|
map = \list, f ->
|
|
when list is
|
|
Cons x xs ->
|
|
Cons (f x) (map xs f)
|
|
|
|
Nil ->
|
|
Nil
|
|
|
|
|
|
isEmpty : ConsList a -> Bool
|
|
isEmpty = \list ->
|
|
when list is
|
|
Cons _ _ ->
|
|
False
|
|
|
|
Nil ->
|
|
True
|