package tablecloth-native

  1. Overview
  2. Docs
val create : 'a -> 'b -> 'c -> 'a * 'b * 'c

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

val first : ('a * 'b * 'c) -> 'a

Extract the first value from a tuple.

Tuple3.first (3, 4, 5) = 3

Tuple3.first ("john", "danger", "doe") = "john"

val second : ('a * 'b * 'c) -> 'b

Extract the second value from a tuple.

Tuple2.second (3, 4, 5) = 4

Tuple2.second ("john", "danger", "doe") = "danger"

val third : ('a * 'b * 'c) -> 'c

Extract the third value from a tuple.

Tuple2.third (3, 4, 5) = 5

Tuple2.third ("john", "danger", "doe") = "doe"

val init : ('a * 'b * 'c) -> 'a * 'b

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)

val tail : ('a * 'b * 'c) -> 'b * 'c

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)

val mapFirst : f:('a -> 'x) -> ('a * 'b * 'c) -> 'x * 'b * 'c

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)

val map_first : f:('a -> 'x) -> ('a * 'b * 'c) -> 'x * 'b * 'c
val mapSecond : f:('b -> 'y) -> ('a * 'b * 'c) -> 'a * 'y * 'c

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)

val map_second : f:('b -> 'y) -> ('a * 'b * 'c) -> 'a * 'y * 'c
val mapThird : f:('c -> 'z) -> ('a * 'b * 'c) -> 'a * 'b * 'z

Transform the third value in a tuple.

Tuple3.mapThird ~f:not ("stressed", 16, false) ("stressed", 16, true)

val map_third : f:('c -> 'z) -> ('a * 'b * 'c) -> 'a * 'b * 'z
val mapEach : f:('a -> 'x) -> g:('b -> 'y) -> h:('c -> 'z) -> ('a * 'b * 'c) -> 'x * 'y * 'z

Transform the third value in a tuple.

Tuple3.mapEach ~f:String.reverse ~g:sqrt ~h:not ("stressed", 16., false) = ("desserts", 4., true)

val map_each : f:('a -> 'x) -> g:('b -> 'y) -> h:('c -> 'z) -> ('a * 'b * 'c) -> 'x * 'y * 'z
val mapAll : f:('a -> 'b) -> ('a * 'a * 'a) -> 'b * 'b * 'b

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)

val map_all : f:('a -> 'b) -> ('a * 'a * 'a) -> 'b * 'b * 'b
val rotateLeft : ('a * 'b * 'c) -> 'b * 'c * 'a

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")

val rotate_left : ('a * 'b * 'c) -> 'b * 'c * 'a
val rotateRight : ('a * 'b * 'c) -> 'c * 'a * 'b

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")

val rotate_right : ('a * 'b * 'c) -> 'c * 'a * 'b
val curry : (('a * 'b * 'c) -> 'd) -> 'a -> 'b -> 'c -> 'd

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]

val uncurry : ('a -> 'b -> 'c -> 'd) -> ('a * 'b * 'c) -> 'd

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

val toList : ('a * 'a * 'a) -> 'a list

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"]

val to_list : ('a * 'a * 'a) -> 'a list
OCaml

Innovation. Community. Security.