Library
Module
Module type
Parameter
Class
Class type
Functions for manipulating trios of values
Functions for manipulating trios of values
Create a Tuple3
.
Examples
Tuple3.create 3 "cat" false = (3, "cat", false)
List.map3 ~f:Tuple3.create [1;2;3] ['a'; 'b'; 'c'] [4.; 5.; 6.] =
[(1, 'a', 4.), (2, 'b', 5.), (3, 'c', 6.)]
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
Tuple3.ofArray [|1; 2;3 |] = Some (1, 2, 3)
Tuple3.ofArray [|1; 2|] = None
Tuple3.ofArray [|4;5;6;7|] = Some (4, 5, 6)
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
Tuple3.ofList [1; 2; 3] = Some (1, 2, 3)
Tuple3.ofList [1; 2] = None
Tuple3.ofList [4; 5; 6; 7] = Some (4, 5, 6)
Extract the first value from a tuple.
Examples
Tuple3.first (3, 4, 5) = 3
Tuple3.first ("john", "danger", "doe") = "john"
Extract the second value from a tuple.
Examples
Tuple.second (3, 4, 5) = 4
Tuple.second ("john", "danger", "doe") = "danger"
Extract the third value from a tuple.
Examples
Tuple.third (3, 4, 5) = 5
Tuple.third ("john", "danger", "doe") = "doe"
Move each value in the tuple one position to the left, moving the value in the first position into the last position.
Examples
Tuple.rotateLeft (3, 4, 5) = (4, 5, 3)
Tuple.rotateLeft ("was", "stressed", "then") = ("stressed", "then", "was")
Move each value in the tuple one position to the right, moving the value in the last position into the first position.
Examples
Tuple.rotateRight (3, 4, 5) = (5, 3, 4)
Tuple.rotateRight ("was", "stressed", "then") = ("then", "was", "stressed")
Transform the first value in a tuple.
Examples
Tuple3.mapFirst ~f:String.reverse ("stressed", 16, false) = ("desserts", 16, false)
Tuple3.mapFirst ~f:String.length ("stressed", 16, false) = (8, 16, false)
Transform the second value in a tuple.
Examples
Tuple3.mapSecond ~f:Float.squareRoot ("stressed", 16., false) = ("stressed", 4., false)
Tuple3.mapSecond ~f:(~-) ("stressed", 16, false) = ("stressed", -16, false)
Transform the third value in a tuple.
Examples
Tuple3.mapThird ~f:not ("stressed", 16, false) ("stressed", 16, true)
Transform all 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
Tuple.mapAll ~f:Float.squareRoot (9., 16., 25.) = (3., 4., 5.)
Tuple.mapAll ~f:String.length ("was", "stressed", "then") = (3, 8, 4)
Turns a tuple into a List
of length three.
This function can only be used on tuples which have the same type for each value.
Examples
Tuple3.toArray (3, 4, 5) = [3; 4; 5]
Tuple3.toArray ("was", "stressed", "then") = ["was"; "stressed"; "then"]
Turns a tuple into a List
of length three.
This function can only be used on tuples which have the same type for each value.
Examples
Tuple3.toList (3, 4, 5) = [3; 4; 5]
Tuple3.toList ("was", "stressed", "then") = ["was"; "stressed"; "then"]
val equal :
('a -> 'a -> bool) ->
('b -> 'b -> bool) ->
('c -> 'c -> bool) ->
('a, 'b, 'c) t ->
('a, 'b, 'c) t ->
bool
Test two Tuple3
s for equality, using the provided functions to test the first, second and third components.
Examples
Tuple.equal Int.equal String.equal Char.equal (1, "Fox", 'j') (1, "Fox", 'k') = true
Tuple.equal Int.equal String.equal Char.equal (1, "Fox", 'j') (2, "Hen", 'j') = false
val compare :
('a -> 'a -> int) ->
('b -> 'b -> int) ->
('c -> 'c -> int) ->
('a, 'b, 'c) t ->
('a, 'b, 'c) t ->
int
Compare two Tuple3
s, using the provided functions to compare the first components then, if the first components are equal, the second components, then the third components
Examples
Tuple.compare Int.compare String.compare Char.compare (1, "Fox", 'j') (1, "Fox", 'j') = 0
Tuple.compare Int.compare String.compare Char.compare (1, "Fox", 'j') (1, "Eel", 'j') = 1
Tuple.compare Int.compare String.compare Char.compare (1, "Fox", 'j') (2, "Fox", 'm') = -1