idris-lang / Idris2

A purely functional programming language with first class types
https://idris-lang.org/
Other
2.53k stars 380 forks source link

[ base ] Add flipped access/update functions for `Sorted{Set,Map,DMap}` #3247

Closed buzden closed 5 months ago

buzden commented 8 months ago

Description

I noticed that I frequently use flip on functions like lookup and contains from Data.Sorted{Set,Map}. I searched for my codebase and realised that 30% of usage of such functions goes with flip. This is pretty common in other codebases, e.g. in the compiler, because sometimes we operate upon known map for a collection of keys or values, so that we want map to be fixed and the rest of the arguments to vary.

So, I propose to add such flipped variants of common functions so that we cover both usecases.

I put all the added functions as public export %inline so that if there were some (postulated) properties on the existing functions, refactoring won't break anything. I also changed several implementations to use newly added functions in the lib. Some of added functions were uncurried, when needed, some were not, I did it in the most usable way in my point of view.

I also along with addition of a new item, slightly improved formatting of code in the CHANGELOG_NEXT.md file, which doesn't worth a separate PR.

Should this change go in the CHANGELOG?

gallais commented 5 months ago

I'm not convinced this is worth doing but no one else is complaining and I'd rather not spend energy on this;