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

Remove duplicate entries in Set.fromList/Dict.fromList #326

Open
jfmengels opened this issue Dec 13, 2024 · 2 comments
Open

Remove duplicate entries in Set.fromList/Dict.fromList #326

jfmengels opened this issue Dec 13, 2024 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jfmengels
Copy link
Owner

jfmengels commented Dec 13, 2024

If some of the keys are the same, then we can remove some of them (potentially telling the user there's a problem with their setup).

Dict.fromList [ ( 1, a ), ( 2, b ), ( 3, c ), ( 1, d ) ]
-->
Dict.fromList [ ( 2, b ), ( 3, c ), ( 1, d ) ]

Dict.fromList [ ( 1, a ), ( 2, b ), ( 3, c ) ]
  |> Dict.insert 1 d
-->
Dict.fromList [ ( 2, b ), ( 3, c ) ]
  |> Dict.insert 1 d
--> Or alternatively put it directly in the list, probably nicer
Dict.fromList [ ( 2, b ), ( 3, c ), ( 1, d ) ]


Set.fromList [ 1, 2, 3, 1 ]
-->
Set.fromList [ 2, 3, 1 ]
--> or remove the later one 🤷 
Set.fromList [ 1, 2, 3 ]

Set.fromList [ 1, 2, 3 ]
  |> Set.insert 1
-->
Set.fromList [ 1, 2, 3 ]
@jfmengels jfmengels added enhancement New feature or request help wanted Extra attention is needed labels Dec 13, 2024
@lue-bird
Copy link
Collaborator

We can also implement these checks for unknown key expressions like

Set.fromList [ a, a ]
--> Set.fromList [ a ]

NaNs do not follow this rule

Set.fromList [ 0/0, 0/0 ]
--> Set.fromList [NaN,NaN]

so we should only do it if expectNaN is configured False.


I think I'll implement some of those

@lue-bird
Copy link
Collaborator

Another simplification we can do is

Dict.fromList [ a, anything, a ]
--> Dict.fromList [ anything, a ]

(again, doesn't work when expecting NaN)

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

No branches or pull requests

2 participants