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