Module Unprime_list.List

include module type of Stdlib.List
type 'a t = 'a list =
| ([])
| (::) of 'a * 'a list
val length : 'a list -> int
val compare_lengths : 'a list -> 'b list -> int
val compare_length_with : 'a list -> int -> int
val cons : 'a -> 'a list -> 'a list
val hd : 'a list -> 'a
val tl : 'a list -> 'a list
val nth : 'a list -> int -> 'a
val nth_opt : 'a list -> int -> 'a option
val rev : 'a list -> 'a list
val init : int -> (int -> 'a) -> 'a list
val append : 'a list -> 'a list -> 'a list
val rev_append : 'a list -> 'a list -> 'a list
val concat : 'a list list -> 'a list
val flatten : 'a list list -> 'a list
val iter : ('a -> unit) -> 'a list -> unit
val iteri : (int -> 'a -> unit) -> 'a list -> unit
val map : ('a -> 'b) -> 'a list -> 'b list
val mapi : (int -> 'a -> 'b) -> 'a list -> 'b list
val rev_map : ('a -> 'b) -> 'a list -> 'b list
val filter_map : ('a -> 'b option) -> 'a list -> 'b list
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
val fold_right : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
val iter2 : ('a -> 'b -> unit) -> 'a list -> 'b list -> unit
val map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
val rev_map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
val fold_left2 : ('a -> 'b -> 'c -> 'a) -> 'a -> 'b list -> 'c list -> 'a
val fold_right2 : ('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c
val for_all : ('a -> bool) -> 'a list -> bool
val exists : ('a -> bool) -> 'a list -> bool
val for_all2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
val exists2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
val mem : 'a -> 'a list -> bool
val memq : 'a -> 'a list -> bool
val find : ('a -> bool) -> 'a list -> 'a
val find_opt : ('a -> bool) -> 'a list -> 'a option
val filter : ('a -> bool) -> 'a list -> 'a list
val find_all : ('a -> bool) -> 'a list -> 'a list
val partition : ('a -> bool) -> 'a list -> 'a list * 'a list
val assoc : 'a -> ('a * 'b) list -> 'b
val assoc_opt : 'a -> ('a * 'b) list -> 'b option
val assq : 'a -> ('a * 'b) list -> 'b
val assq_opt : 'a -> ('a * 'b) list -> 'b option
val mem_assoc : 'a -> ('a * 'b) list -> bool
val mem_assq : 'a -> ('a * 'b) list -> bool
val remove_assoc : 'a -> ('a * 'b) list -> ('a * 'b) list
val remove_assq : 'a -> ('a * 'b) list -> ('a * 'b) list
val split : ('a * 'b) list -> 'a list * 'b list
val combine : 'a list -> 'b list -> ('a * 'b) list
val sort : ('a -> 'a -> int) -> 'a list -> 'a list
val stable_sort : ('a -> 'a -> int) -> 'a list -> 'a list
val fast_sort : ('a -> 'a -> int) -> 'a list -> 'a list
val sort_uniq : ('a -> 'a -> int) -> 'a list -> 'a list
val merge : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
val to_seq : 'a list -> 'a Stdlib.Seq.t
val of_seq : 'a Stdlib.Seq.t -> 'a list
include module type of Prime_list
val sample : (int -> 'a) -> int -> 'a list

sample f n returns [f 0; …; f (n - 1)].

val of_option : 'a option -> 'a list

of_option None is [] and of_option (Some x) is [x].

val count : ('a -> bool) -> 'a list -> int

count f xs is the number of elements x of xs for which f x holds.

search f xs returns the first element of map f xs which is different from None or None if all elements are None. This is an alternative to find which is easy to nest, e.g. the function Prime_array.search (Prime_option.search (Prime_list.search f)) returns the first non-None mapping of f in an array of optional lists.

Comparison

val equal : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool

equal f xs ys is true iff xs and ys have the same length and f x y is true for all corresponding elements x and y in xs and ys.

val compare : ('a -> 'b -> int) -> 'a list -> 'b list -> int

compare f xs ys is the lexicographic comparison of xs and ys using f to compare corresponding pairs of elements.

Iteration

val fold : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b

fold f [x₁; …; xₙ] returns the composition f xₙ ∘ ⋯ ∘ f x₁. This is fold_left with parameters reordered to make it more composable.

val rev_filter : ('a -> bool) -> 'a list -> 'a list

rev_filter xs is rev (filter xs) but faster.

val fmap : ('a -> 'b option) -> 'a list -> 'b list
val filter_map : ('a -> 'b option) -> 'a list -> 'b list

filter_map f xs is the list of all y such that f x = Some y for some x in xs, and having the same order as the corresponding elemets of xs. This provides an optimisation of map Option.get (filter ((<>) None) (map f xs)).

val flatten_map : ('a -> 'b list) -> 'a list -> 'b list

flatten_map f xs is a tail-recursive optimisation of flatten (map f xs).

val rev_flatten : 'a list list -> 'a list

rev_flatten is rev ∘ flatten.

Iteration over Two Lists

val iter2t : ('a -> 'b -> unit) -> 'a list -> 'b list -> unit

iter2t f [x₁; …; xₙ] [y₁; …; yₘ] calls f x₁ y₁; …; f xₗ yₗ in order, where l = min n m. This is a truncating variant of iter2 from the standard library.

val map2t : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list

map2t f [x₁; …; xₙ] [y₁; …; yₘ] returns [f x₁ y₁; ⋯; f xₗ yₗ] where l = min n m. The t suffix indicates truncation, otherwise this behaves like map2 from the standard library.

val rev_map2t : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list

rev_map2t f is an optimisation of rev ∘ map2t f.

val fold2 : ('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c

fold2 f g [x₁; …; xₙ] [y₁; …; yₘ] returns f (xₙ, yₙ) ∘ ⋯ ∘ f (x₁, y₁) and n = m and raises Invalid_argument if n ≠ m.

val fold2t : ('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c

fold2t f g [x₁; …; xₙ] [y₁; …; yₘ] returns f (xₗ, yₗ) ∘ ⋯ ∘ f (x₁, y₁) where l = min n m. The t suffix indicates truncation.

Differential Iteration

val map_diff : ('a -> 'a -> 'b) -> 'a list -> 'b list

map_diff f [x₁; …; xₙ] returns f x₁ x₂; f x₂ x₃; …; f xₙ₋₁ xₙ.

raises Invalid_argument

on the empty list.

val rev_map_diff : ('a -> 'a -> 'b) -> 'a list -> 'b list

rev_map_diff f is an optimisation of rev ∘ map_diff f.

Sublists

val drop : int -> 'a list -> 'a list

drop n xs returns the suffix of xs following the n first elements. Raises Failure if xs is shorter than n elements and Invalid_argument if n is negative.

val take : int -> 'a list -> 'a list

take n xs returns the n-element prefix of xs. Raises Failure if xs is shorter than n elements and Invalid_argument if n is negative.

val drop_while : ('a -> bool) -> 'a list -> 'a list

drop_while f xs returns the longest suffix of xs which does not start with an element on which f is true.

val take_while : ('a -> bool) -> 'a list -> 'a list

take_while f xs returns the longest prefix of xs containing only elements which f maps to true.

Combining Lists

val interfix : 'a -> 'a list -> 'a list

interfix x [y₁; y₂; ...; yₙ₋₁; yₙ] is [y₁; x; y₂; ...; yₙ₋₁; x; yₙ].

raises Failure

if ys = [].

val rev_interfix : 'a -> 'a list -> 'a list

rev_interfix x ys is List.rev (concat x ys).