Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
wish: after functions in ordered types like Map or Set #4952
Original bug ID: 4952
Il would be quite useful to be able to get, inside a Map, the entry (if any) after a given key.
So I would dream of an additional function inside Map.S
(** [after k m] retrieve the next key, that is the lowest [nk] such that the map [m] contains a binding for [nk] and with [nk] compared greater than [k]. If no such key exist, raises [Not_found] **)
Likewise, it would be useful to be able to get, inside a Set, the element (if any) next to a given one.
So I would dream of an additional function inside Set.S
(** [next x s] returns the element [y] after the given [x] in set [s], or raises [Not_found] if no such element exist (i.e. if [s] is empty or if [x] is the maximal element. *)
The wished Set.S.next can be defined using Set.S.split (but that might not be efficient) and Set.S.min.
One could also wish the dual Set.S.previous.
Both functions have the following uses:
Happy New Year 2010!