Add `take`/`drop`/`splitAt` to `Data.Map`/`Data.Set`
Bardur Arantsson
spam at scientician.net
Tue Mar 8 06:43:06 UTC 2016
On 03/08/2016 01:14 AM, Gabriel Gonzalez wrote:
> I would like to propose adding `take`/`drop`/`splitAt` to both `Data.Map` and `Data.Set` as originally requested in:
>
> https://github.com/haskell/containers/issues/135 <https://github.com/haskell/containers/issues/135>
>
> The motivation behind this proposal is three-fold:
>
> * for convenience - these functions are commonly used to implement pagination or previews of maps/sets
> * for type accuracy - the public API impose an unnecessary `Ord` constraint
> * for efficiency - these can be implemented more efficiently using the internal API
>
> Currently the only way you can implement this functionality via the public API is to
> use `lookupIndex`/`elemAt` + `split`. For example, one way to
implement `Data.Set.take` is:
>
+1
It also seems like a more idiomatic Haskell API to have "take", "drop",
"splitAt" operations rather than[1] "lookupIndex/elemAt" + "split".
[1] I realize the latter aren't going away.
Regards,
More information about the Libraries
mailing list