Stdlib.Pair(3)
π Stdlib.Pair(3) π
okay bestie, welcome to the OCaml library manual β this one's Stdlib.Pair, and ngl it's giving "tiny module, huge main character energy" β¨
πΈ NAME πΈ
Stdlib.Pair β no description π (yes fr, the docs literally just say "no description", we're working with what we've got)
π Module π
Module Stdlib.Pair
π¦ Documentation π¦
Module Pair : (module Stdlib__Pair)
π Pairs π
type ('a, 'b) t = 'a * 'b
The type for pairs. that's it, that's the whole vibe π
val make : 'a -> 'b -> 'a * 'b
make a b is the pair (a, b) .
val fst : 'a * 'b -> 'a
fst (a, b) is a . first one, front of the line, main character π«Ά
val snd : 'a * 'b -> 'b
snd (a, b) is b . second one, still iconic, don't forget her π
val swap : 'a * 'b -> 'b * 'a
swap (a, b) is (b, a) . literally trading places, no cap π₯
π Iterators π
val fold : ('a -> 'b -> 'c) -> 'a * 'b -> 'c
fold f (a, b) applies f to a and b .
val map : ('a -> 'c) -> ('b -> 'd) -> 'a * 'b -> 'c * 'd
map f g (a, b) applies f to a and g to b . each component gets her own glow-up β¨
val iter : ('a -> unit) -> ('b -> unit) -> 'a * 'b -> unit
iter f g (a, b) first applies f to a , and then g to b . order matters bestie, f goes first π
val map_fst : ('a -> 'c) -> 'a * 'b -> 'c * 'b
map_fst f p applies f to p 's first component.
val map_snd : ('b -> 'c) -> 'a * 'b -> 'a * 'c
map_snd f p applies f to p 's second component.
π§ Predicates and comparisons π§
val equal : ('a -> 'a -> bool) -> ('b -> 'b -> bool) -> 'a * 'b -> 'a * 'b -> bool
equal eqa eqb (a1, b1) (a2, b2) is true if and only if eqa a1 a2 and eqb b1 b2 are both true . both of them, like a duo, no skipping π
val compare : ('a -> 'a -> int) -> ('b -> 'b -> int) -> 'a * 'b -> 'a * 'b -> int
compare cmpa cmpb is a total order on pairs using cmpa to compare the first component, and cmpb to compare the second component. It is implemented by a lexicographic order. lowkey fancy, highkey lexicographic π
ok real talk β this whole module is just pairs, so there's nothing scary here. no deprecated stuff, no gotchas, no "undefined behaviour, proceed at your own risk" energy. just vibes and tuples π
πΈ that's the whole page bestie, you ate πΈ
sign-off time π«Ά: this was rendered from the OCaml library manual, page Stdlib.Pair(3), generated by OCamldoc and dated 2026-06-22. slay, periodt π
β¨
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms