package tablecloth-base
Module Tablecloth.Tuple3Source
Functions for manipulating tuples of length three
Functions for manipulating trios of values
Create
Create a Tuple3.
Examples
Tuple3.make 3 "cat" false = (3, "cat", false) List.map3 ~f:Tuple3.make [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.from_array [|1; 2;3 |] = Some (1, 2, 3)Tuple3.from_array [|1; 2|] = NoneTuple3.from_array [|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.from_list [1; 2; 3] = Some (1, 2, 3)Tuple3.from_list [1; 2] = NoneTuple3.from_list [4; 5; 6; 7] = Some (4, 5, 6)Extract the first value from a tuple.
Examples
Tuple3.first (3, 4, 5) = 3Tuple3.first ("john", "danger", "doe") = "john"Extract the second value from a tuple.
Examples
Tuple3.second (3, 4, 5) = 4Tuple3.second ("john", "danger", "doe") = "danger"Extract the third value from a tuple.
Examples
Tuple3.third (3, 4, 5) = 5Tuple3.third ("john", "danger", "doe") = "doe"Modify
Move each value in the tuple one position to the left, moving the value in the first position into the last position.
Examples
Tuple3.rotate_left (3, 4, 5) = (4, 5, 3)Tuple3.rotate_left ("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
Tuple3.rotate_right (3, 4, 5) = (5, 3, 4)Tuple3.rotate_right ("was", "stressed", "then") = ("then", "was", "stressed")Transform the first value in a tuple.
Examples
Tuple3.map_first ~f:String.reverse ("stressed", 16, false) = ("desserts", 16, false)Tuple3.map_first ~f:String.length ("stressed", 16, false) = (8, 16, false)Transform the second value in a tuple.
Examples
Tuple3.map_second ~f:Float.square_root ("stressed", 16., false) = ("stressed", 4., false)Tuple3.map_second ~f:(~-) ("stressed", 16, false) = ("stressed", -16, false)Transform the third value in a tuple.
Examples
Tuple3.map_third ~f:not ("stressed", 16, false) ("stressed", 16, true)Transform all the values of a tuple using the same function.
map_all can only be used on tuples which have the same type for each value.
Examples
Tuple3.map_all ~f:Float.square_root (9., 16., 25.) = (3., 4., 5.)Tuple3.map_all ~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.to_array (3, 4, 5) = [|3; 4; 5|]Tuple3.to_array ("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.to_list (3, 4, 5) = [3; 4; 5]Tuple3.to_list ("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 ->
boolTest two Tuple3s for equality, using the provided functions to test the first, second and third components.
Examples
Tuple3.equal Int.equal String.equal Char.equal (1, "Fox", 'j') (1, "Fox", 'k') = trueTuple3.equal Int.equal String.equal Char.equal (1, "Fox", 'j') (2, "Hen", 'j') = falseval compare :
f:('a -> 'a -> int) ->
g:('b -> 'b -> int) ->
h:('c -> 'c -> int) ->
('a, 'b, 'c) t ->
('a, 'b, 'c) t ->
intCompare two Tuple3s, using f to compare the first components then, if the first components are equal, the second components are compared with g, then the third components are compared with h
Examples
Tuple3.compare ~f:Int.compare ~g:String.compare ~h:Char.compare (1, "Fox", 'j') (1, "Fox", 'j') = 0Tuple3.compare ~f:Int.compare ~g:String.compare ~h:Char.compare (1, "Fox", 'j') (1, "Eel", 'j') = 1Tuple3.compare ~f:Int.compare ~g:String.compare ~h:Char.compare (1, "Fox", 'j') (2, "Fox", 'm') = -1