module Container_intf:sig
..end
Container.S0
or Container.S1
in the signature
for every container-like data structure (Array, List, String, ...) to ensure a
consistent interface.Container.S0
or Container.S1
in the signature
for every container-like data structure (Array, List, String, ...) to ensure a
consistent interface.module type S0 =sig
..end
module type S0_phantom =sig
..end
module type S1 =sig
..end
module type S1_phantom_invariant =sig
..end
module type S1_phantom =sig
..end
module type S1_permissions =sig
..end
module type Generic =sig
..end
module type Generic_phantom =sig
..end
module type Make_arg =sig
..end
module type Container =sig
..end
Container.S0
or Container.S1
in the signature
for every container-like data structure (Array, List, String, ...) to ensure a
consistent interface.equal
function if it is notiter
must allow exceptions raised in f
to escape, terminating the iteration
cleanly. The same holds for all functions below taking an f
.fold t ~init ~f
returns f (... f (f (f init e1) e2) e3 ...) en
, where e1..en
are the elements of t
true
if and only if there exists an element for which the provided
function evaluates to true
. This is a short-circuiting operation.true
if and only if the provided function evaluates to true
for all
elements. This is a short-circuiting operation.f i
for i in the containeroption
the first element for which f
evaluates to true.f
that returns Some
, and returns None
if there
is no such element.cmp
function. In case of a tie, the first element encountered while traversing the
collection is returned. The implementation uses fold
so it has the same
complexity as fold
. Returns None
iff the collection is empty.equal
function if it is notfold t ~init ~f
returns f (... f (f (f init e1) e2) e3 ...) en
, where e1..en
are the elements of t
true
if and only if there exists an element for which the provided
function evaluates to true
. This is a short-circuiting operation.true
if and only if the provided function evaluates to true
for all
elements. This is a short-circuiting operation.f i
for i in the containeroption
the first element for which f
evaluates to true.f
that returns Some
, and returns None
if there
is no such element.cmp
function, or None
if the collection is empty. In case of a tie, the first element
encountered while traversing the collection is returned.equal
is not providedfold t ~init ~f
returns f (... f (f (f init e1) e2) e3 ...) en
, where e1..en
are the elements of t
true
if and only if there exists an element for which the provided
function evaluates to true
. This is a short-circuiting operation.true
if and only if the provided function evaluates to true
for all
elements. This is a short-circuiting operation.f i
for i in the containeroption
the first element for which f
evaluates to true.f
that returns Some
, and returns None
if there
is no such element.cmp
function, or None
if the collection is empty. In case of a tie, the first
element encountered while traversing the collection is returned. The implementation
uses fold
so it has the same complexity as fold
.equal
is not providedfold t ~init ~f
returns f (... f (f (f init e1) e2) e3 ...) en
, where e1..en
are the elements of t
true
if and only if there exists an element for which the provided
function evaluates to true
. This is a short-circuiting operation.true
if and only if the provided function evaluates to true
for all
elements. This is a short-circuiting operation.f i
for i in the containeroption
the first element for which f
evaluates to true.f
that returns Some
, and returns None
if there
is no such element.cmp
function. In case of a tie, the first element encountered while traversing the
collection is returned. The implementation uses fold
so it has the same complexity
as fold
. Returns None
iff the collection is empty.equal
is not providedfold t ~init ~f
returns f (... f (f (f init e1) e2) e3 ...) en
, where e1..en
are the elements of t
true
if and only if there exists an element for which the provided
function evaluates to true
. This is a short-circuiting operation.true
if and only if the provided function evaluates to true
for all
elements. This is a short-circuiting operation.f i
for i in the containeroption
the first element for which f
evaluates to true.f
that returns Some
, and returns None
if there
is no such element.cmp
function. In case of a tie, the first element encountered while traversing the
collection is returned. The implementation uses fold
so it has the same complexity
as fold
. Returns None
iff the collection is empty.iter
argument to Container.Make
says how to implement the container's iter
function. `Define_using_fold
means to define iter
via:
iter t ~f = Container.iter ~fold t ~f
`Custom
overrides the default implementation, presumably with something more
efficient. Several other functions returned by Container.Make
are defined in
terms of iter
, so passing in a more efficient iter
will improve their efficiency
as well.
Generic definitions of container operations in terms of fold
.
E.g.: iter ~fold t ~f = fold t ~init:() ~f:(fun () a -> f a)
.
Generic definitions of container operations in terms of iter
.
The idiom for using Container.Make
is to bind the resulting module and to
explicitly import each of the functions that one wants:
module C = Container.Make (struct ... end)
let count = C.count
let exists = C.exists
let find = C.find
...
This is preferable to:
include Container.Make (struct ... end)
because the include
makes it too easy to shadow specialized implementations of
container functions (length
being a common one).