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 a value? #4

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

insert should append a value? #4

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

Comments

@amitaibu
Copy link

Currently we prepend the new value and it appears on the top of the list.

D (( key, value ) :: alteredAlist)

This means that if we have a list

[ ( 1, 1 ), ( 2, 2 ), ( 3, 3 ), ( 4, 4 ) ] |> Dict.fromList

results with D [(4,4),(3,3),(2,2),(1,1)]

I'd expect the list order to remain as is, or is there a good reason not to?

@amitaibu
Copy link
Author

amitaibu commented Feb 18, 2019

Another good example is

[ ( 1, 1 ), ( 2, 2 ), ( 3, 3 ), ( 4, 4 ) ] 
    |> Dict.fromList 
    |> Dict.toList

ends up with [(4,4),(3,3),(2,2),(1,1)]

@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 added a commit to amitaibu/assoc-list that referenced this issue Feb 18, 2019
@pzp1997
Copy link
Owner

pzp1997 commented Feb 19, 2019

I agree with you that the behavior is a bit surprising. This was one of the aspects of the library that I was the most unsure about before publishing. The reason fromList reverses the list is because it uses List.foldl rather than List.foldr. At the time this seemed like the right choice to me for two reasons, List.foldl is a bit faster and it is what elm/core Dict uses in its fromList implementation. In hindsight, this decision feels more and more like a mistake to me.

With regards to changing insert, that is not a great way to solve this problem since appends are way slower than conses both in theory and in practice. We could do a trick by writing a combined filter-and-append operation using List.foldr but it seems like more trouble than its worth given that there's an even simpler fix involving fromList. In short, the "problem" is with fromList not insert.

I want to make the change to fromList but might need to wait for another breaking change so I can batch them and trick Elm's automatic semver enforcement into accepting this as a major bump.

@pzp1997 pzp1997 modified the milestones: 1.1.0, 2.0.0 Feb 19, 2019
@amitaibu
Copy link
Author

Hi, just checking if there's a plan to change this soon? (currently I'm running a local patched lib, but would be happy to use upstream)

@pzp1997
Copy link
Owner

pzp1997 commented Apr 28, 2019

I am going to try to release a new version once I am done with school in about two weeks and I expect this change to be included. Hang in there!

@amitaibu
Copy link
Author

Hi 👋

Anything I can help to get it forward? I just added the forked file to the 4th Gizra project, and I feel bad about it every time! 😉

@amitaibu
Copy link
Author

Hi @pzp1997 are you still interested in this fix? We're now at the ~7th project with our own fork.

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

Successfully merging a pull request may close this issue.

2 participants