1Stdlib.Option(3) OCaml library Stdlib.Option(3)
2
3
4
6 Stdlib.Option - no description
7
9 Module Stdlib.Option
10
12 Module Option
13 : (module Stdlib__Option)
14
15
16
17
18
19
20
21
22
23 Options
24 type 'a t = 'a option =
25 | None
26 | Some of 'a
27
28
29 The type for option values. Either None or a value Some v .
30
31
32
33 val none : 'a option
34
35
36 none is None .
37
38
39
40 val some : 'a -> 'a option
41
42
43 some v is Some v .
44
45
46
47 val value : 'a option -> default:'a -> 'a
48
49
50 value o ~default is v if o is Some v and default otherwise.
51
52
53
54 val get : 'a option -> 'a
55
56
57 get o is v if o is Some v and raise otherwise.
58
59
60 Raises Invalid_argument if o is None .
61
62
63
64 val bind : 'a option -> ('a -> 'b option) -> 'b option
65
66
67 bind o f is f v if o is Some v and None if o is None .
68
69
70
71 val join : 'a option option -> 'a option
72
73
74 join oo is Some v if oo is Some (Some v) and None otherwise.
75
76
77
78 val map : ('a -> 'b) -> 'a option -> 'b option
79
80
81 map f o is None if o is None and Some (f v) if o is Some v .
82
83
84
85 val fold : none:'a -> some:('b -> 'a) -> 'b option -> 'a
86
87
88 fold ~none ~some o is none if o is None and some v if o is Some v .
89
90
91
92 val iter : ('a -> unit) -> 'a option -> unit
93
94
95 iter f o is f v if o is Some v and () otherwise.
96
97
98
99
100 Predicates and comparisons
101 val is_none : 'a option -> bool
102
103
104 is_none o is true if and only if o is None .
105
106
107
108 val is_some : 'a option -> bool
109
110
111 is_some o is true if and only if o is Some o .
112
113
114
115 val equal : ('a -> 'a -> bool) -> 'a option -> 'a option -> bool
116
117
118 equal eq o0 o1 is true if and only if o0 and o1 are both None or if
119 they are Some v0 and Some v1 and eq v0 v1 is true .
120
121
122
123 val compare : ('a -> 'a -> int) -> 'a option -> 'a option -> int
124
125
126 compare cmp o0 o1 is a total order on options using cmp to compare val‐
127 ues wrapped by Some _ . None is smaller than Some _ values.
128
129
130
131
132 Converting
133 val to_result : none:'e -> 'a option -> ('a, 'e) result
134
135
136 to_result ~none o is Ok v if o is Some v and Error none otherwise.
137
138
139
140 val to_list : 'a option -> 'a list
141
142
143 to_list o is [] if o is None and [v] if o is Some v .
144
145
146
147 val to_seq : 'a option -> 'a Seq.t
148
149
150 to_seq o is o as a sequence. None is the empty sequence and Some v is
151 the singleton sequence containing v .
152
153
154
155
156
157OCamldoc 2023-07-20 Stdlib.Option(3)