package tablecloth-native
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=0c71dd4035d6fa4978baabc3c932dba3
sha512=44ba09f1ff43e61403703cc244e91e0f8062bd9da998f031430d701a4de148b02878f7f881303f6ded261176f21926ab5ba00a313510ed8e2d2f252b3fd00054
doc/tablecloth-native/Tablecloth/Tuple2/index.html
Module Tablecloth.Tuple2
Functions for manipulating tuples of length two
Functions for manipulating pairs of values
Create
Create a two-tuple with the given values.
The values do not have to be of the same type.
Examples
Tuple2.make 3 "Clementine" = (3, "Clementine")Create a tuple from the first two elements of an Array.
If the array is longer than two elements, the extra elements are ignored.
If the array is less than two elements, returns None
Examples
Tuple2.fromArray [|1; 2|] = Some (1, 2)Tuple2.fromArray [|1|] = NoneTuple2.fromArray [|4; 5; 6|] = Some (4, 5)Create a tuple from the first two elements of a List.
If the list is longer than two elements, the extra elements are ignored.
If the list is less than two elements, returns None
Examples
Tuple2.fromList [1; 2] = Some (1, 2)Tuple2.fromList [1] = NoneTuple2.fromList [4; 5; 6] = Some (4, 5)Extract the first value from a tuple.
Examples
Tuple2.first (3, 4) = 3Tuple2.first ("john", "doe") = "john"Extract the second value from a tuple.
Examples
Tuple2.second (3, 4) = 4Tuple2.second ("john", "doe") = "doe"Transform
Transform the first value in a tuple.
Examples
Tuple2.mapFirst ~f:String.reverse ("stressed", 16) = ("desserts", 16)Tuple2.mapFirst ~f:String.length ("stressed", 16) = (8, 16)Transform the second value in a tuple.
Examples
Tuple2.mapSecond ~f:Float.squareRoot ("stressed", 16.) = ("stressed", 4.)Tuple2.mapSecond ~f:(~-) ("stressed", 16) = ("stressed", -16)Transform both values of a tuple, using f for the first value and g for the second.
Examples
Tuple2.mapEach ~f:String.reverse ~g:Float.squareRoot ("stressed", 16.) = ("desserts", 4.)Tuple2.mapEach ~f:String.length ~g:(~-) ("stressed", 16) = (8, -16)Transform both of the values of a tuple using the same function.
mapAll can only be used on tuples which have the same type for each value.
Examples
Tuple2.mapAll ~f:(Int.add 1) (3, 4, 5) = (4, 5, 6)Tuple2.mapAll ~f:String.length ("was", "stressed") = (3, 8)Switches the first and second values of a tuple.
Examples
Tuple2.swap (3, 4) = (4, 3)Tuple2.swap ("stressed", 16) = (16, "stressed")Convert
Turns a tuple into an Array of length two.
This function can only be used on tuples which have the same type for each value.
Examples
Tuple2.toArray (3, 4) = [|3; 4|]Tuple2.toArray ("was", "stressed") = [|"was"; "stressed"|]Turns a tuple into a list of length two. This function can only be used on tuples which have the same type for each value.
Examples
Tuple2.toList (3, 4) = [3; 4]Tuple2.toList ("was", "stressed") = ["was"; "stressed"]Compare
Test two Tuple2s for equality, using the provided functions to test the first and second components.
Examples
Tuple2.equal Int.equal String.equal (1, "Fox") (1, "Fox") = trueTuple2.equal Int.equal String.equal (1, "Fox") (2, "Hen") = falseCompare two Tuple2s, using the provided functions to compare the first components then, if the first components are equal, the second components.
Examples
Tuple2.compare Int.compare String.compare (1, "Fox") (1, "Fox") = 0Tuple2.compare Int.compare String.compare (1, "Fox") (1, "Eel") = 1Tuple2.compare Int.compare String.compare (1, "Fox") (2, "Hen") = -1