Misc.Stdlib.String.Set(3)

πŸ’… Misc.Stdlib.String.Set πŸ’…

okay so bestie, welcome to the Misc.Stdlib.String.Set page ✨ β€” this one lives in the OCaml library manual, and it's literally the string-specialised set module, no cap. It's giving "ordered collections of strings that behave" πŸŽ€. Buckle up, we're going through every single val, and yes, I mean every one 🫢.


🌸 NAME 🌸

Misc.Stdlib.String.Set β€” no description 😭 (the manpage really said "figure it out yourself", iconic honestly)


🧚 Module 🧚

Module Misc.Stdlib.String.Set


✨ Documentation ✨

Module Set : sig end

So the whole thing is a Set module signature, and inside it there are tidy little themed clusters. Let's go section by section, bestie πŸ’–.


πŸŽ€ Sets πŸŽ€

  • type elt β€” the type of the set elements. iykyk, this is the thing you're putting inside the set πŸ”₯
  • type t β€” the type of sets themselves. the main character type πŸ‘‘
  • val empty : t β€” the empty set. the blank canvas, the clean slate, the "no thoughts head empty" of sets πŸ’€
  • val add : elt -> t -> t β€” add x s returns a set containing all elements of s, plus x. If x was already in s, s is returned unchanged (the result of the function is then physically equal to s). Note the caveat below, bestie, it's important:
Before 4.03, physical equality was not ensured. πŸ•°οΈ
  • val singleton : elt -> t β€” singleton x returns the one-element set containing only x. just one (1) little guy, and honestly? she ate 🌸
  • val remove : elt -> t -> t β€” remove x s returns a set containing all elements of s, except x. If x was not in s, s is returned unchanged (the result of the function is then physically equal to s). Same lore as add:
Before 4.03, physical equality was not ensured. πŸ•°οΈ
  • val union : t -> t -> t β€” set union. combine era 🫢
  • val inter : t -> t -> t β€” set intersection. the overlap, the "we have so much in common" moment πŸ’–
  • val disjoint : t -> t -> bool β€” test if two sets are disjoint. literally zero chemistry, nothing shared πŸ’€
Since 4.08
  • val diff : t -> t -> t β€” set difference: diff s1 s2 contains the elements of s1 that are not in s2. it's the "you're not invited to my birthday" operation πŸ™ˆ
  • val cardinal : t -> int β€” return the number of elements of a set. the headcount, the attendance list πŸ“‹

πŸ¦‹ Elements πŸ¦‹

  • val elements : t -> elt list β€” return the list of all elements of the given set. The returned list is sorted in increasing order with respect to the ordering Ord.compare, where Ord is the argument given to Set.Make. sorted, organised, never chaotic ✨
  • val min_elt : t -> elt β€” return the smallest element of the given set (with respect to the Ord.compare ordering), or raise Not_found if the set is empty. the littlest one πŸ₯Ί
  • val min_elt_opt : t -> elt option β€” return the smallest element of the given set (with respect to the Ord.compare ordering), or None if the set is empty. same vibe, but in a cute option wrapper πŸŽ€
Since 4.05
  • val max_elt : t -> elt β€” same as Set.S.min_elt, but returns the largest element of the given set. big energy πŸ‘‘
  • val max_elt_opt : t -> elt option β€” same as Set.S.min_elt_opt, but returns the largest element of the given set. big energy, option edition πŸ”₯
Since 4.05
  • val choose : t -> elt β€” return one element of the given set, or raise Not_found if the set is empty. Which element is chosen is unspecified, but equal elements will be chosen for equal sets. so like, don't get attached to which one shows up πŸ™ˆ
  • val choose_opt : t -> elt option β€” return one element of the given set, or None if the set is empty. Which element is chosen is unspecified, but equal elements will be chosen for equal sets. the option version of a surprise 🌈
Since 4.05

πŸ” Searching πŸ”

  • val find : elt -> t -> elt β€” find x s returns the element of s equal to x (according to Ord.compare), or raise Not_found if no such element exists. the "do you have this in my size" of functions πŸ›οΈ
Since 4.01
  • val find_opt : elt -> t -> elt option β€” find_opt x s returns the element of s equal to x (according to Ord.compare), or None if no such element exists. πŸŽ€
Since 4.05
  • val find_first : (elt -> bool) -> t -> elt β€” find_first f s, where f is a monotonically increasing function, returns the lowest element e of s such that f e, or raises Not_found if no such element exists.

For example, find_first (fun e -> Ord.compare e x >= 0) s will return the first element e of s where Ord.compare e x >= 0 (intuitively: e >= x), or raise Not_found if x is greater than any element of s. πŸ’…

Since 4.05
  • val find_first_opt : (elt -> bool) -> t -> elt option β€” find_first_opt f s, where f is a monotonically increasing function, returns an option containing the lowest element e of s such that f e, or None if no such element exists. 🌸
Since 4.05
  • val find_last : (elt -> bool) -> t -> elt β€” find_last f s, where f is a monotonically decreasing function, returns the highest element e of s such that f e, or raises Not_found if no such element exists. (note: decreasing here, bestie, don't mix it up 😭)
Since 4.05
  • val find_last_opt : (elt -> bool) -> t -> elt option β€” find_last_opt f s, where f is a monotonically decreasing function, returns an option containing the highest element e of s such that f e, or None if no such element exists. πŸ¦‹
Since 4.05

🧚 Traversing 🧚

  • val iter : (elt -> unit) -> t -> unit β€” iter f s applies f in turn to all elements of s. The elements of s are presented to f in increasing order with respect to the ordering over the type of the elements. one at a time, in order, like a well-behaved queue πŸŽ€
  • val fold : (elt -> 'acc -> 'acc) -> t -> 'acc -> 'acc β€” fold f s init computes (f xN ... (f x2 (f x1 init))...), where x1 ... xN are the elements of s, in increasing order. the classic accumulation ritual ✨

πŸ”₯ Transforming πŸ”₯

  • val map : (elt -> elt) -> t -> t β€” map f s is the set whose elements are f a0, f a1 ... f aN, where a0, a1 ... aN are the elements of s.

The elements are passed to f in increasing order with respect to the ordering over the type of the elements.

If no element of s is changed by f, s is returned unchanged. (If each output of f is physically equal to its input, the returned set is physically equal to s.)

Since 4.04
  • val filter : (elt -> bool) -> t -> t β€” filter f s returns the set of all elements in s that satisfy predicate f. If every element in s satisfies f, s is returned unchanged (the result of the function is then physically equal to s). the glow-up filter, only the yeses survive πŸ’…
Before 4.03, physical equality was not ensured. πŸ•°οΈ
  • val filter_map : (elt -> elt option) -> t -> t β€” filter_map f s returns the set of all v such that f x = Some v for some element x of s.

For example, filter_map (fun n -> if n mod 2 = 0 then Some (n / 2) else None) s is the set of halves of the even elements of s. πŸ“

If no element of s is changed or dropped by f (if f x = Some x for each element x), then s is returned unchanged: the result of the function is then physically equal to s. πŸ‘‘

Since 4.11
  • val partition : (elt -> bool) -> t -> t * t β€” partition f s returns a pair of sets (s1, s2), where s1 is the set of all the elements of s that satisfy the predicate f, and s2 is the set of all the elements of s that do not satisfy f. two friend groups, no drama 🌈
  • val split : elt -> t -> t * bool * t β€” split x s returns a triple (l, present, r), where l is the set of elements of s that are strictly less than x; r is the set of elements of s that are strictly greater than x; present is false if s contains no element equal to x, or true if s contains an element equal to x. a little triptych, we love a structured answer πŸŽ€

⭐ Predicates and comparisons ⭐

  • val is_empty : t -> bool β€” test whether a set is empty or not. vibe check: is there anything in here πŸ«™
  • val is_singleton : t -> bool β€” test whether a set has exactly one element or not. one (1) element, no more, no less πŸ₯Ί
Since 5.5
  • val mem : elt -> t -> bool β€” mem x s tests whether x belongs to the set s. are you on the list or not πŸ’€
  • val equal : t -> t -> bool β€” equal s1 s2 tests whether the sets s1 and s2 are equal, that is, contain equal elements. twin behavior 🌸
  • val compare : t -> t -> int β€” total ordering between sets. Can be used as the ordering function for doing sets of sets. sets inside sets, it's giving inception πŸŒ€
  • val subset : t -> t -> bool β€” subset s1 s2 tests whether the set s1 is a subset of the set s2. is every one of mine also one of yours 🫢
  • val for_all : (elt -> bool) -> t -> bool β€” for_all f s checks if all elements of the set satisfy the predicate f. unanimous or nothing ✨
  • val exists : (elt -> bool) -> t -> bool β€” exists f s checks if at least one element of the set satisfies the predicate f. just one is enough, we're not picky πŸ’–

πŸ’œ Converting πŸ’œ

  • val to_list : t -> elt list β€” to_list s is Set.S.elements s. just a rebrand, same slay πŸŽ€
Since 5.1
  • val of_list : elt list -> t β€” of_list l creates a set from a list of elements. This is usually more efficient than folding add over the list, except perhaps for lists with many duplicated elements. so use it, but like, watch out for the dupes πŸ™ˆ
Since 4.02
  • val to_seq_from : elt -> t -> elt Seq.t β€” to_seq_from x s iterates on a subset of the elements of s in ascending order, from x or above. start here and go up ⬆️
Since 4.07
  • val to_seq : t -> elt Seq.t β€” iterate on the whole set, in ascending order. all of it, smallest to biggest 🌸
Since 4.07
  • val to_rev_seq : t -> elt Seq.t β€” iterate on the whole set, in descending order. all of it, biggest to smallest, reverse chronology πŸ’…
Since 4.12
  • val add_seq : elt Seq.t -> t -> t β€” add the given elements to the set, in order. pouring them in one by one πŸ«—
Since 4.07
  • val of_seq : elt Seq.t -> t β€” build a set from the given elements. from sequence to set, the glow-up pipeline ✨
Since 4.07

🫢 ok that's the whole page, bestie 🫢

That's literally everything β€” every val, every Since tag, every "physical equality was not ensured" warning, nothing skipped, periodt πŸ’….

And a lil' sign-off: this page was generated by OCamldoc and it's dated 2026-06-22, and it's the Misc.Stdlib.String.Set(3) page, in case you need to cite your sources for the group chat πŸ˜ŒπŸ’–.

ngl, go write some sets now β€” you've got this πŸ‘‘πŸŒˆ
πŸ“¦ where this page comes from