package tablecloth-native
Library
Module
Module type
Parameter
Class
Class type
Create a 3-tuple.
Tuple3.create 3 4 5 = (3, 4, 5)
let zip3 (xs : 'a list) (ys : 'b list) (zs : 'c list) : ('a * 'b * 'c) list = List.map3 ~f:Tuple3.create xs ys zs
Extract the first value from a tuple.
Tuple3.first (3, 4, 5) = 3
Tuple3.first ("john", "danger", "doe") = "john"
Extract the second value from a tuple.
Tuple2.second (3, 4, 5) = 4
Tuple2.second ("john", "danger", "doe") = "danger"
Extract the third value from a tuple.
Tuple2.third (3, 4, 5) = 5
Tuple2.third ("john", "danger", "doe") = "doe"
Extract the first and second values of a 3-tuple as a 2-tuple.
Tuple2.init (3, "stressed", false) = (3, "stressed")
Tuple2.init ("john", 16, "doe") = ("john", 16)
Extract the second and third values of a 3-tuple as a 2-tuple.
Tuple2.init (3, "stressed", false) = ("stressed", false)
Tuple2.init ("john", 16, false) = (16, false)
Transform the first value in a tuple.
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.
Tuple3.mapSecond ~f:sqrt ("stressed", 16., false) = ("stressed", 4., false)
Tuple3.mapSecond ~f:(~-) ("stressed", 16, false) = ("stressed", -16, false)
Transform the third value in a tuple.
Tuple3.mapThird ~f:not ("stressed", 16, false) ("stressed", 16, true)
Transform the third value in a tuple.
Tuple3.mapEach ~f:String.reverse ~g:sqrt ~h:not ("stressed", 16., false) = ("desserts", 4., 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.
Tuple2.mapAll ~f:sqrt (9., 16., 25.) = (3., 4., 5.)
Tuple2.mapAll ~f:String.length ("was", "stressed", "then") = (3, 8, 4)
Move each value in the tuple one position to the left, moving the value in the first position into the last position.
Tuple2.rotateLeft (3, 4, 5) = (4, 5, 3)
Tuple2.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.
Tuple2.rotateRight (3, 4, 5) = (5, 3, 4)
Tuple2.rotateRight ("was", "stressed", "then") = ("then", "was", "stressed")
curry f
takes a function f
which takes a single argument of a tuple 'a * 'b *'c
and returns a function which takes three arguments that can be partially applied.
let cubeVolume (width, height, depth) = width * height * depth
let curriedVolume : float -> float -> float = curry squareArea
let depths = [3; 4; 5]
List.map depths ~f:(curriedArea 3 4) = [36; 48; 60]
uncurry f
takes a function f
which takes three arguments and returns a function which takes a single argument of a 3-tuple
let sum (a : int) (b : int) (c : int) : int = a + b + c
let uncurriedSum : (int * int * int) -> int = uncurry sum
uncurriedSum (3, 4, 5) = 12
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.
Tuple3.toList (3, 4, 5) = [3; 4; 5]
Tuple3.toList ("was", "stressed", "then") = ["was"; "stressed"; "then"]