package batteries
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=b691e5870f876c6e590d6aa51b4c5457
sha512=3b0643ff337cd70da8c4b77887d212e82d043a7163fca36588be12186bc86bbcf0d56b13349325f12eabb96c846204c88560786342f50af7bf4e20b9480d3964
doc/batteries.unthreaded/BatTuple/index.html
Module BatTuple
Source
Tuples.
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.
Creation. Functions make
take n
arguments and build a n
-tuple.
Projection. Functions first
, second
, third
, fourth
, and 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 first
and 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 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, Tuple3.map
f g h
will apply f
, g
, and 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 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 print
prints a tuple given a method for printing each of its elements. The simpler 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.
Pairs. Some of the functions here are also exposed in Pervasives
, as documented below.