package alg_structs

  1. Overview
  2. Docs

Non-empty lists

type 'a t

The type of lists which cannot be empty.

include Functor.S with type 'a t := 'a t
include Functor.Seed with type 'a t := 'a t
val map : f:('a -> 'b) -> 'a t -> 'b t

map ~f maps the function f : 'a -> 'b to a function 'f T : 'a T -> 'b T.

As an example, if T (x : u) : u t then map ~(f:u -> v) (T x) is T (f x) : v t. As a result, map is often thought of as applying f "in" T.

The function map is the mapping of arrows, taking every arrow 'a -> 'b to an arrow 'a t -> 'b t.

val (<@>) : ('a -> 'b) -> 'a t -> 'b t

Infix for map

val (|>>) : 'a t -> ('a -> 'b) -> 'b t

Mapped version of |> (which is flipped (<&>))

val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

See List.equal.

val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int

See List.compare.

val cons : 'a -> 'a t -> 'a t

See List.cons.

val uncons : 'a t -> 'a * 'a list

uncons t is (List.hd t, List.tl t).

val hd : 'a t -> 'a

hd t is the first element of t.

Since t is non-empty, it is guaranteed that there will always be a head.

val tl : 'a t -> 'a list

tl t are the elements of t after, but not including the head.

Since t is non-empty, it is guaranteed that there will always be a tail.

val append : 'a t -> 'a t -> 'a t

See List.append.

val op : 'a t -> 'a t -> 'a t

An alias for append.

val fold : ('a -> 'a -> 'a) -> 'a t -> 'a

See List.concat.

val of_list : 'a list -> 'a t option

of_list xs is a Some non-empty list of xs if xs isn't empty. Otherwise it is None.

val to_list : 'a t -> 'a list

to_list t is the list of the elements in t.

OCaml

Innovation. Community. Security.