NOTE: API changes are expected in a future release.
Modules are provided for tuples with 2, 3, 4, and 5 elements. Each provides the following categories of functions.
n arguments and build a
fifth extract a single element. Also, multiple elements can be extracted. For example,
Tuple3.get13 returns the first and third elements of a 3-tuple. All possible combinations are provided.
Note there are no
get functions in Tuple2 because
second already cover all possibilities. However,
swap is provided, which can be thought of as projecting items in a different order.
Mapping. Apply a function to one or all elements of a tuple. Functions
map2, etc. map a given function to the first, second, etc. element of a tuple. All elements can be mapped using
mapn. For example,
f g h will apply
h to the three elements, respectively, of a 3-tuple. Function
mapn is similar but applies the same function to all elements, which thus requires the elements to be of the same type.
Currying. Every tuple has a
uncurry function, which allow converting between functions that take
n arguments to ones that take a single
n-tuple can be converted to an enum with
n elements using its
enum function, and can be constructed from an enum using
of_enum. Tuples satisfy
printn function can be used when all elements are of the same type.
Comparison. Every tuple has a
compare function, which can optionally be customized by specifying methods for comparing each element.
Pervasives.compare is used by default.
module Tuple2 : sig ... end
Pairs. Some of the functions here are also exposed in
Pervasives, as documented below.
module Tuple3 : sig ... end
module Tuple4 : sig ... end
module Tuple5 : sig ... end