jfmengels/elm-review-simplify

Remove duplicate entries in Set.fromList/Dict.fromList

Open

#326 opened on Dec 13, 2024

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Elm (10 forks)github user discovery
enhancementhelp wanted

Repository metrics

Stars
 (22 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

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 ]

Contributor guide