1Stdlib.Either(3) OCaml library Stdlib.Either(3)
2
3
4
6 Stdlib.Either - no description
7
9 Module Stdlib.Either
10
12 Module Either
13 : (module Stdlib__Either)
14
15
16
17
18
19
20
21 type ('a, 'b) t =
22 | Left of 'a
23 | Right of 'b
24
25
26 A value of ('a, 'b) Either.t contains either a value of 'a or a value
27 of 'b
28
29
30
31
32 val left : 'a -> ('a, 'b) t
33
34
35 left v is Left v .
36
37
38
39 val right : 'b -> ('a, 'b) t
40
41
42 right v is Right v .
43
44
45
46 val is_left : ('a, 'b) t -> bool
47
48
49 is_left (Left v) is true , is_left (Right v) is false .
50
51
52
53 val is_right : ('a, 'b) t -> bool
54
55
56 is_right (Left v) is false , is_right (Right v) is true .
57
58
59
60 val find_left : ('a, 'b) t -> 'a option
61
62
63 find_left (Left v) is Some v , find_left (Right _) is None
64
65
66
67
68 val find_right : ('a, 'b) t -> 'b option
69
70
71 find_right (Right v) is Some v , find_right (Left _) is None
72
73
74
75
76 val map_left : ('a1 -> 'a2) -> ('a1, 'b) t -> ('a2, 'b) t
77
78
79 map_left f e is Left (f v) if e is Left v and e if e is Right _ .
80
81
82
83 val map_right : ('b1 -> 'b2) -> ('a, 'b1) t -> ('a, 'b2) t
84
85
86 map_right f e is Right (f v) if e is Right v and e if e is Left _ .
87
88
89
90 val map : left:('a1 -> 'a2) -> right:('b1 -> 'b2) -> ('a1, 'b1) t ->
91 ('a2, 'b2) t
92
93
94 map ~left ~right (Left v) is Left (left v) , map ~left ~right (Right v)
95 is Right (right v) .
96
97
98
99 val fold : left:('a -> 'c) -> right:('b -> 'c) -> ('a, 'b) t -> 'c
100
101
102 fold ~left ~right (Left v) is left v , and fold ~left ~right (Right v)
103 is right v .
104
105
106
107 val iter : left:('a -> unit) -> right:('b -> unit) -> ('a, 'b) t ->
108 unit
109
110
111 iter ~left ~right (Left v) is left v , and iter ~left ~right (Right v)
112 is right v .
113
114
115
116 val for_all : left:('a -> bool) -> right:('b -> bool) -> ('a, 'b) t ->
117 bool
118
119
120 for_all ~left ~right (Left v) is left v , and for_all ~left ~right
121 (Right v) is right v .
122
123
124
125 val equal : left:('a -> 'a -> bool) -> right:('b -> 'b -> bool) -> ('a,
126 'b) t -> ('a, 'b) t -> bool
127
128
129 equal ~left ~right e0 e1 tests equality of e0 and e1 using left and
130 right to respectively compare values wrapped by Left _ and Right _ .
131
132
133
134 val compare : left:('a -> 'a -> int) -> right:('b -> 'b -> int) -> ('a,
135 'b) t -> ('a, 'b) t -> int
136
137
138 compare ~left ~right e0 e1 totally orders e0 and e1 using left and
139 right to respectively compare values wrapped by Left _ and Right _ .
140 Left _ values are smaller than Right _ values.
141
142
143
144
145
146OCamldoc 2022-02-04 Stdlib.Either(3)