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

[ new ] added util functions for SortedMap #3254

Merged
merged 2 commits into from
Jun 11, 2024

Conversation

claudio-etterli
Copy link
Contributor

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?

  • If this is a fix, user-facing change, a compiler change, or a new paper
    implementation, I have updated CHANGELOG_NEXT.md (and potentially also
    CONTRIBUTORS.md).

Comment on lines +31 to +36
export
insertWith : (v -> v -> v) -> k -> v -> SortedMap k v -> SortedMap k v
insertWith f k v xs =
case lookup k xs of
Just x => insert k (f v x) xs
Nothing => insert k v xs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a direct corollary of update so not sure it's needed?

@stefan-hoeck
Copy link
Contributor

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.

@gallais gallais merged commit 0174618 into idris-lang:main Jun 11, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants