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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
type ('a, 'b) t = 'a * 'b
let make a b = (a, b)
let fromArray array =
match array with
| [||] | [| _ |] ->
None
| [| a; b |] ->
Some (a, b)
| _ ->
None
let from_array = fromArray
let fromList list =
match list with [] | [ _ ] -> None | a :: b :: _rest -> Some (a, b)
let from_list = fromList
let first (a, _) = a
let second (_, b) = b
let mapFirst (a, b) ~f = (f a, b)
let map_first = mapFirst
let mapSecond (a, b) ~f = (a, f b)
let map_second = mapSecond
let mapEach (a, b) ~f ~g = (f a, g b)
let map_each = mapEach
let mapAll (a1, a2) ~f = (f a1, f a2)
let map_all = mapAll
let swap (a, b) = (b, a)
let toArray (a, b) = [| a; b |]
let to_array = toArray
let toList (a, b) = [ a; b ]
let to_list = toList
let equal equalFirst equalSecond (a, b) (a', b') =
equalFirst a a' && equalSecond b b'
let compare compareFirst compareSecond (a, b) (a', b') =
match compareFirst a a' with 0 -> compareSecond b b' | result -> result