std.list
A linked list type.
Types
A linked list type
let list @ { List, ? } = import! std.list
let { assert_neq } = import! std.test
assert_neq (Cons 1 Nil) Nil
Values
Constructs a list from an array. Useful to emulate list literals
let { ? } = import! std.effect
let list @ { List, ? } = import! std.list
let { assert_eq, ? } = import! std.test
seq assert_eq (list.of [1, 2]) (Cons 1 (Cons 2 Nil))
let xs : List String = list.of []
assert_eq xs Nil
let many ?alt x : forall a f . [Alternative f] -> f a -> f (List a)
let some ?alt x : forall a f . [Alternative f] -> f a -> f (List a)
Applies predicate
to each element in the list and returns a new list containing only of the
elements where predicate
returns True
let { ? } = import! std.effect
let list @ { List, ? } = import! std.list
let { assert_eq, ? } = import! std.test
seq assert_eq (list.filter (\x -> x /= 2) (list.of [1, 2, 3])) (list.of [1, 3])
assert_eq (list.filter (\x -> False) (list.of [1, 2, 3])) Nil
Sorts the list using ord
.
let list @ { List, ? } = import! std.list
let { assert_eq, ? } = import! std.test
assert_eq (list.sort (list.of [2, 1, 3])) (list.of [1, 2, 3])
Eq a
defines equality (==) on a
Ord a
defines an ordering on a
Semigroup a
represents an associative operation on a
.
This means the following laws must hold:
forall x . append x (append y z) == append (append x y) z
Monoid a
represents an semigroup an which has an identity. This means
the following additional laws must hold:
forall x . append x empty == x
forall x . append empty x == x
A Functor
represents an action on a parameterized type which does not
change the structure with the mapped type.
The following laws should hold:
map id == id
map (f << g) == map f << map g
#[implicit]
let applicative : Applicative List
A Functor
with application.
The following laws should hold:
wrap id <*> v = v
wrap (<<) <*> u <*> v <*> w = u <*> (v <*> w)
wrap f <*> wrap x = wrap (f x)
u <*> wrap y = wrap (\g -> g x) <*> u
#[implicit]
let alternative : Alternative List
A monoid on applicative functors.
A generalised interface for imperatively sequencing actions
Operations over a data structure that can be folded which means that a functions gets called on
each element to reduce the structure to a single value (Array
, List
and Map
are all Foldable
)
#[implicit]
let traversable : Traversable List
Show a
represents a conversion function from a
to a readable string.