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

insert should behave as upsert, or add upset? #5

Open
amitaibu opened this issue Feb 18, 2019 · 5 comments
Open

insert should behave as upsert, or add upset? #5

amitaibu opened this issue Feb 18, 2019 · 5 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@amitaibu
Copy link

I guess this one is a matter of use case, but currently if an element exists, it's being removed and the new element (with the same key) is now in the head of the list.

(D alteredAlist) =
remove key dict

So, maybe we need to add a new function that will maintain the position of the element, only change the value?

@pzp1997
Copy link
Owner

pzp1997 commented Feb 18, 2019

Would the update function accomplish what you need by chance?

@amitaibu
Copy link
Author

Hi @pzp1997 👋 The advantage of upsert is that it's either insert OR update, with the caller not having to bother with checking which should happen (in a way same as core's Dict.insert is actually both an insert or update)

@pzp1997
Copy link
Owner

pzp1997 commented Feb 18, 2019

You could always do Dict.update key (always (Just value)) dict but I agree that we can make this more obvious by adding an upsert function. I'll put it on the docket for 1.1.0.

@pzp1997 pzp1997 self-assigned this Feb 18, 2019
@pzp1997 pzp1997 added the enhancement New feature or request label Feb 18, 2019
@pzp1997 pzp1997 added this to the 1.1.0 milestone Feb 18, 2019
@amitaibu
Copy link
Author

Actually, I think that it should be the default behavior of insert, as we had here:

https://github.com/Gizra/elm-dictlist/blob/ad680d1cf32504ff57aeb03f286b39f0ae676440/src/AllDictList.elm#L887-L891

@Herteby
Copy link

Herteby commented Feb 14, 2020

Yeah having it as the default behavior for insert seems better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants