Stdlib.Option(3)

πŸ’– NAME πŸ’–

okay bestie, so this page is Stdlib.Option, and it's comin' at you straight from the OCaml library manual, which is the whole vibe of this doc. ngl the original NAME section literally just says "no description" 😭 so like... that's the description. we move.


🌸 Module 🌸

the module is Stdlib.Option. that's it, that's the line. iconic minimalism.


✨ Documentation ✨

so we're chillin' in Module Option, and it's officially:

(module Stdlib__Option)

lowkey just a re-export situation, but slay, let's get into it 🫢

πŸŽ€ Options πŸŽ€

first up, the actual type, the main character:

type 'a t = 'a option =
 | None
 | Some of 'a

this is the type for option values β€” fr fr it's either None, or a value wrapped up as Some v. two moods, no in-between πŸ’…


  • val none : 'a option β€” none is literally None. that's the whole job. queen of doing nothing ✨
  • val some : 'a -> 'a option β€” some v gives you Some v. wrap it up, we're done 🎁
  • val value : 'a option -> default:'a -> 'a β€” value o ~default is v when o is Some v, and it's default otherwise. the ultimate fallback bestie 🫢
  • val get : 'a option -> 'a β€” get o is v when o is Some v, and it raises otherwise.
🚨 heads up bestie: this one raises Invalid_argument if o is None. no cap, it will NOT be chill about it 😭
  • val bind : 'a option -> ('a -> 'b option) -> 'b option β€” bind o f is f v if o is Some v, and None if o is None. chaining era πŸ’«
  • val join : 'a option option -> 'a option β€” join oo is Some v if oo is Some (Some v), and None otherwise. un-nesting the nesting, we love a flatten πŸ¦‹
  • val map : ('a -> 'b) -> 'a option -> 'b option β€” map f o is None if o is None, and Some (f v) if o is Some v. glow-up transformation sequence ✨
  • val product : 'a option -> 'b option -> ('a * 'b) option β€” product o0 o1 is Some (v0, v1) if o0 is Some v0 and o1 is Some v1, and None otherwise. Since 5.5 ⭐
  • val fold : none:'a -> some:('b -> 'a) -> 'b option -> 'a β€” fold ~none ~some o is none if o is None, and some v if o is Some v. pick your fighter based on the vibe πŸŽ€
  • val iter : ('a -> unit) -> 'a option -> unit β€” iter f o is f v if o is Some v, and () otherwise. do the thing, or don't, no pressure πŸ’…
  • val blend : ('a -> 'a -> 'a) -> 'a option -> 'a option -> 'a option β€” blend f o1 o2 is o1 if o2 is None, it's o2 if o1 is None, and it's Some (f v1 v2) if o1 is Some v1 and o2 is Some v2. merging energies, we're obsessed πŸ”₯ Since 5.5 ⭐
  • val for_all : ('a -> bool) -> 'a option -> bool β€” for_all p behaves like List.for_all p on a list of zero or one element:
    • for_all p None is true,
    • for_all p (Some v) is p v.

Since 5.5 ⭐

  • val exists : ('a -> bool) -> 'a option -> bool β€” exists p behaves like List.exists p on a list of zero or one element:
    • exists p None is false,
    • exists p (Some v) is p v.

Since 5.5 ⭐

πŸ¦‹ Predicates and comparisons πŸ¦‹

the "is it or isn't it" era, plus ranking your options, literally:

  • val is_none : 'a option -> bool β€” is_none o is true if and only if o is None. vibe check: empty βœ…
  • val is_some : 'a option -> bool β€” is_some o is true if and only if o is Some o. vibe check: occupied βœ…
  • val equal : ('a -> 'a -> bool) -> 'a option -> 'a option -> bool β€” equal eq o0 o1 is true if and only if o0 and o1 are both None, or if they're Some v0 and Some v1 and eq v0 v1 is true. twin flames or nothin' πŸ’–
  • val compare : ('a -> 'a -> int) -> 'a option -> 'a option -> int β€” compare cmp o0 o1 is a total order on options, using cmp to compare the values wrapped by Some _. and bestie, None is smaller than Some _ values. ranking rules, periodt πŸ‘‘

🌈 Converting 🌈

glow-ups into other types, no cap:

  • val to_result : none:'e -> 'a option -> ('a, 'e) result β€” to_result ~none o is Ok v if o is Some v, and Error none otherwise. switching lanes to result-land πŸš—
  • val to_list : 'a option -> 'a list β€” to_list o is [] if o is None, and [v] if o is Some v. zero or one bestie, that's the list πŸ“
  • val to_seq : 'a option -> 'a Seq.t β€” to_seq o is o as a sequence. None is the empty sequence, and Some v is the singleton sequence containing v. stream it 🌊

πŸ’œ Syntax πŸ’œ

module Syntax : sig end

binding operators, bestie! see manual section 12.23 for the deets.

Since 5.5 ⭐


🧚 and that's the whole page, no notes. every flag, every val, every "Since 5.5", every raise β€” all present and accounted for πŸ’…

cute little sign-off: this masterpiece was brought to you by OCamldoc, dated 2026-06-22, and it lives at Stdlib.Option(3). mwah πŸ’‹ slay and read your manual pages, bestie πŸŽ€βœ¨

πŸ“¦ where this page comes from