idris-lang / Idris2

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

[ new ] added util functions for SortedMap #3254

Closed claudio-etterli closed 3 weeks ago

claudio-etterli commented 2 months ago

Description

Added insertWith, insertFromWith and fromListWith to the SortedMap module. The idea is to insert key-value pairs and decide how duplicated values should be merged. Unique key-values pairs will be appended to the SortedMap.

Should this change go in the CHANGELOG?

stefan-hoeck commented 3 weeks ago

I had a look at Haskell's Data.Map today, and I am in strong favour of adding the utilities from this PR (including insertWith). The Haskell module has a function like Data.SortedMap.update (it's called alter there) as well as insertWith, fromListWith, and several other related utilities.

In my own code, the need for insertWith comes up quite frequently, while I hardly ever used update so far, probably because it is much more comon to add something to a SortedMap than to delete stuff.