std.list

A linked list type.

Types

type List a = 
    | Nil
    | Cons a (std.list.List a)

A linked list type

let list @ { List, ? } = import! std.list
let { assert } = import! std.test

assert (Cons 1 Nil /= Nil)

Values

let of xs : forall a . Array a -> std.list.List a

Constructs a list from an array. Useful to emulate list literals

let list @ { List, ? } = import! std.list
let { assert } = import! std.test

assert (list.of [1, 2] == Cons 1 (Cons 2 Nil))
let xs : List String = list.of []
assert (xs == Nil)

let many ?alt x : forall a a0 . [std.alternative.Alternative a] -> a a0 -> a (std.list.List a0)

let some ?alt x : forall a a0 . [std.alternative.Alternative a] -> a a0 -> a (std.list.List a0)

let filter predicate xs : forall a . (a -> std.types.Bool) -> std.list.List a -> std.list.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 list @ { List, ? } = import! std.list
let { assert } = import! std.test
assert (list.filter (\x -> x /= 2) (list.of [1, 2, 3]) == list.of [1, 3])
assert (list.filter (\x -> False) (list.of [1, 2, 3]) == Nil)

let sort xs : forall a . [std.cmp.Ord a] -> std.list.List a -> std.list.List a

Sorts the list using ord.

let list @ { List, ? } = import! std.list
let { assert } = import! std.test
assert (list.sort (list.of [2, 1, 3]) == list.of [1, 2, 3])

let eq : forall a . [std.cmp.Eq a] -> std.cmp.Eq (std.list.List a)

Eq a defines equality (==) on a

let ord ?ord : forall a . [std.cmp.Ord a] -> std.cmp.Ord (std.list.List a)

Ord a defines an ordering on a

let semigroup : forall a . std.semigroup.Semigroup (std.list.List 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

let monoid : forall a . std.monoid.Monoid (std.list.List a)

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

let functor : std.functor.Functor std.list.List

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

let applicative : std.applicative.Applicative std.list.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

let alternative : std.alternative.Alternative std.list.List

A monoid on applicative functors.

let monad : std.monad.Monad std.list.List

A generalised interface for imperatively sequencing actions

let foldable : std.foldable.Foldable std.list.List

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)

let traversable : std.traversable.Traversable std.list.List

let show ?d : forall a . [std.show.Show a] -> std.show.Show (std.list.List a)

Show a represents a conversion function from a to a readable string.