package tablecloth-base

  1. Overview
  2. Docs
Native OCaml library implementing Tablecloth, a cross-platform standard library for OCaml and Rescript

Install

Dune Dependency

Authors

Maintainers

Sources

0.0.9.tar.gz
md5=eef8da54ae2e373fc38a08bb761ea973
sha512=c74de7cf90798c6c2702a21f40d340da3fa2405f00ccc193568a04d6b0e08a41b47d5db35c0ed7662043f1fe223c2e82212e162a64f67c3577dece6660c08b20

doc/src/tablecloth-base/TableclothTuple2.ml.html

Source file TableclothTuple2.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
type ('a, 'b) t = 'a * 'b

let make a b = (a, b)

let from_array array =
  match array with
  | [||] | [| _ |] ->
      None
  | [| a; b |] ->
      Some (a, b)
  | _ ->
      Some (array.(0), array.(1))


let from_array = from_array

let from_list list =
  match list with [] | [ _ ] -> None | a :: b :: _rest -> Some (a, b)


let first (a, _) = a

let second (_, b) = b

let map_first (a, b) ~f = (f a, b)

let map_second (a, b) ~f = (a, f b)

let map_each (a, b) ~f ~g = (f a, g b)

let map_all (a1, a2) ~f = (f a1, f a2)

let swap (a, b) = (b, a)

let to_array (a, b) = [| a; b |]

let to_list (a, b) = [ a; b ]

let equal equal_first equal_second (a, b) (a', b') =
  equal_first a a' && equal_second b b'


let compare ~f:compare_first ~g:compare_second (a, b) (a', b') =
  match compare_first a a' with 0 -> compare_second b b' | result -> result
OCaml

Innovation. Community. Security.