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 append element #6

Closed
wants to merge 1 commit into from
Closed

Conversation

amitaibu
Copy link

fixes #4

-}
insert : k -> v -> Dict k v -> Dict k v
insert key value dict =
let
(D alteredAlist) =
remove key dict
in
D (( key, value ) :: alteredAlist)
D (List.concat [ alteredAlist, [ ( key, value ) ] ])
Copy link
Author

Choose a reason for hiding this comment

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

Maybe this should be replaced in that case with update key (always (Just value)) dict, as suggested in #5

Copy link
Author

Choose a reason for hiding this comment

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

and then in update we'd have

                Just alteredValue ->
-                   D (( targetKey, alteredValue ) :: alist)
+                   D (List.concat [ alist, [ ( targetKey, alteredValue ) ] ])

@pzp1997 makes sense?

Copy link
Owner

Choose a reason for hiding this comment

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

I don't want to write insert in terms of update because that would slow down inserts which are probably the most common Dict operation for most use cases.

@pzp1997
Copy link
Owner

pzp1997 commented Feb 19, 2019

Thanks for the PR— I am going to close it because I don't think it is the right approach to solving #4. See my comments in that issue for more info.

@pzp1997 pzp1997 closed this Feb 19, 2019
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.

insert should append a value?
2 participants