Module Unprime_list.List
include module type of Stdlib.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 count : ('a -> bool) -> 'a list -> int
count f xs
is the number of elementsx
ofxs
for whichf x
holds.
val search : ('a -> 'b option) -> 'a list -> 'b option
search f xs
returns the first element ofmap f xs
which is different fromNone
orNone
if all elements areNone
. This is an alternative tofind
which is easy to nest, e.g. the functionPrime_array.search (Prime_option.search (Prime_list.search f))
returns the first non-None
mapping off
in an array of optional lists.
Comparison
Iteration
val fold : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
fold f [x₁; …; xₙ]
returns the compositionf xₙ ∘ ⋯ ∘ f x₁
. This isfold_left
with parameters reordered to make it more composable.
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 ally
such thatf x = Some y
for somex
inxs
, and having the same order as the corresponding elemets ofxs
. This provides an optimisation ofmap Option.get (filter ((<>) None) (map f xs))
.
Iteration over Two Lists
val iter2t : ('a -> 'b -> unit) -> 'a list -> 'b list -> unit
iter2t f [x₁; …; xₙ] [y₁; …; yₘ]
callsf x₁ y₁; …; f xₗ yₗ
in order, wherel = min n m
. This is a truncating variant ofiter2
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ₗ]
wherel = min n m
. Thet
suffix indicates truncation, otherwise this behaves likemap2
from the standard library.
val rev_map2t : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
rev_map2t f
is an optimisation ofrev ∘ map2t f
.
Differential Iteration
Sublists
val drop : int -> 'a list -> 'a list
drop n xs
returns the suffix ofxs
following then
first elements. RaisesFailure
ifxs
is shorter thann
elements and Invalid_argument ifn
is negative.
val take : int -> 'a list -> 'a list
take n xs
returns then
-element prefix ofxs
. RaisesFailure
ifxs
is shorter thann
elements and Invalid_argument ifn
is negative.