Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wish: after functions in ordered types like Map or Set #4952

Closed
vicuna opened this issue Jan 2, 2010 · 1 comment
Closed

wish: after functions in ordered types like Map or Set #4952

vicuna opened this issue Jan 2, 2010 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Jan 2, 2010

Original bug ID: 4952
Reporter: Basile Starynkevitch
Assigned to: @alainfrisch
Status: resolved (set by @alainfrisch on 2016-12-07T17:32:32Z)
Resolution: fixed
Priority: normal
Severity: feature
Fixed in version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Category: standard library

Bug description

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] **)
val after: key -> 'a t -> key

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. *)
val next: elt -> t -> elt

Additional information

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:

  • the notion of good orders in math.

  • in general, implement iterating co-routines (or iteration in CPS style) in Set-s or Map-s.

  • in particular, they would be quite useful in some graphical interface applications. For example, suppose one code an editor using LabGtk & GText.buffer & GText.view. If one wants to have some sensitive words or text fragments, it would be useful to find e.g. the iter after a given line, etc..

Happy New Year 2010!

Regards.

--
Basile Starynkevitch

@vicuna
Copy link
Author

vicuna commented Dec 7, 2016

Comment author: @alainfrisch

Addressed by Map.find_first/find_last in 4.05.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants