Stdlib.Either(3) OCaml library Stdlib.Either(3)

# [NAME](#NAME)

Stdlib.Either - no description

# [Module](#Module)

Module Stdlib.Either

# [Documentation](#Documentation)

Module **Either**  
: **(module Stdlib\_\_Either)**

*type* **('a, 'b)** *t* =  
| Left **of** **'a**  
| Right **of** **'b**

A value of **('a, 'b) Either.t** contains either a value of **'a** or a value of **'b**

*val left* : **'a -&gt; ('a, 'b) t**

**left v** is **Left v** .

*val right* : **'b -&gt; ('a, 'b) t**

**right v** is **Right v** .

*val is\_left* : **('a, 'b) t -&gt; bool**

**is\_left (Left v)** is **true** , **is\_left (Right v)** is **false** .

*val is\_right* : **('a, 'b) t -&gt; bool**

**is\_right (Left v)** is **false** , **is\_right (Right v)** is **true** .

*val get\_left* : **('a, 'b) t -&gt; 'a**

**get\_left e** is **v** if **e** is **Left v** and raise otherwise.

**Since** 5.4

**Raises Invalid\_argument** if **e** is **Right \_** .

*val get\_right* : **('a, 'b) t -&gt; 'b**

**get\_right e** is **v** if **e** is **Right v** and raise otherwise.

**Since** 5.4

**Raises Invalid\_argument** if **e** is **Left \_** .

*val find\_left* : **('a, 'b) t -&gt; 'a option**

**find\_left (Left v)** is **Some v** , **find\_left (Right \_)** is **None**

*val find\_right* : **('a, 'b) t -&gt; 'b option**

**find\_right (Right v)** is **Some v** , **find\_right (Left \_)** is **None**

*val map\_left* : **('a1 -&gt; 'a2) -&gt; ('a1, 'b) t -&gt; ('a2, 'b) t**

**map\_left f e** is **Left (f v)** if **e** is **Left v** and **e** if **e** is **Right \_** .

*val map\_right* : **('b1 -&gt; 'b2) -&gt; ('a, 'b1) t -&gt; ('a, 'b2) t**

**map\_right f e** is **Right (f v)** if **e** is **Right v** and **e** if **e** is **Left \_** .

*val map* : **left:('a1 -&gt; 'a2) -&gt;** **right:('b1 -&gt; 'b2) -&gt; ('a1, 'b1) t -&gt; ('a2, 'b2) t**

**map ~left ~right (Left v)** is **Left (left v)** , **map ~left ~right (Right v)** is **Right (right v)** .

*val fold* : **left:('a -&gt; 'c) -&gt; right:('b -&gt; 'c) -&gt; ('a, 'b) t -&gt; 'c**

**fold ~left ~right (Left v)** is **left v** , and **fold ~left ~right (Right v)** is **right v** .

*val retract* : **('a, 'a) t -&gt; 'a**

**retract (Left v)** is **v** , and **retract (Right v)** is **v** .

**Since** 5.4

*val iter* : **left:('a -&gt; unit) -&gt; right:('b -&gt; unit) -&gt; ('a, 'b) t -&gt; unit**

**iter ~left ~right (Left v)** is **left v** , and **iter ~left ~right (Right v)** is **right v** .

*val for\_all* : **left:('a -&gt; bool) -&gt; right:('b -&gt; bool) -&gt; ('a, 'b) t -&gt; bool**

**for\_all ~left ~right (Left v)** is **left v** , and **for\_all ~left ~right (Right v)** is **right v** .

*val equal* : **left:('a -&gt; 'a -&gt; bool) -&gt;** **right:('b -&gt; 'b -&gt; bool) -&gt; ('a, 'b) t -&gt; ('a, 'b) t -&gt; bool**

**equal ~left ~right e0 e1** tests equality of **e0** and **e1** using **left** and **right** to respectively compare values wrapped by **Left \_** and **Right \_** .

*val compare* : **left:('a -&gt; 'a -&gt; int) -&gt;** **right:('b -&gt; 'b -&gt; int) -&gt; ('a, 'b) t -&gt; ('a, 'b) t -&gt; int**

**compare ~left ~right e0 e1** totally orders **e0** and **e1** using **left** and **right** to respectively compare values wrapped by **Left \_** and **Right \_** . **Left \_** values are smaller than **Right \_** values.

2026-10-23 OCamldoc

---

Document: Stdlib.Either(3o) from ocaml 5.5.2-r0 (Chainguard OS)
Source: https://github.com/ocaml/ocaml
