package batteries

  1. Overview
  2. Docs
A community-maintained standard library extension

Install

Dune Dependency

Authors

Maintainers

Sources

v3.5.1.tar.gz
md5=d3d16ffc960e832a1c0e21b7123194e9
sha512=36c8561079aa9fefc864c2f03bd8ae20aa05987bb67e7a9beac3ab4f440dbf7d44f141c172b05fddb1a5b618fc55a27962bb45fc39bd7b3a15d56e0ed3ff3870

doc/batteries.unthreaded/BatTuple/index.html

Module BatTuple

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.

module Tuple2 : sig ... end

Pairs. Some of the functions here are also exposed in Pervasives, as documented below.

module Tuple3 : sig ... end

Triples.

module Tuple4 : sig ... end

4-Tuples.

module Tuple5 : sig ... end

5-Tuples.

OCaml

Innovation. Community. Security.