module BatTuple:Tuples. Modules are provided for tuples with 2, 3, 4, and 5 elements. Each provides the following categories of functions.sig
..end
Projection. Functions first
, second
, third
, fourth
, and fifth
extract a single element. Also, multiple elements can be
extracted. For example, BatTuple.Tuple3.prj13
returns the first and
third elements of a 3-tuple. All possible combinations are
provided. Note there are no prj
functions in Tuple2 because
first
and second
already cover all possibilities.
Mapping. Apply a function to one or all elements of a
tuple. Functions map1
, map2
, etc. map a given function to the
first, second, etc. element of a tuple. All elements can be mapped
using map
or mapn
. For example, BatTuple.Tuple3.mapn
f g h
will apply f
, g
, and h
to the three elements, respectively,
of a 3-tuple. Function map
is similar but applies the same
function to all elements, which thus requires the elements to be
of the same type. Tuples satisfy BatInterfaces.Mappable
.
Currying. Every tuple has a curry
and uncurry
function, which
allow converting between functions that take n
arguments to ones
that take a single n
-tuple argument.
Enumeration. Every 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 BatEnum.Enumerable
.
Printing. Function printn
prints a tuple given a method for
printing each of its elements. The simpler print
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
module Tuple3:sig
..end
module Tuple4:sig
..end
module Tuple5:sig
..end