jfmengels/elm-review-simplify

Remove duplicate entries in Set.fromList/Dict.fromList

Open

#326 aperta il 13 dic 2024

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)Elm (10 fork)github user discovery
enhancementhelp wanted

Metriche repository

Star
 (22 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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 ]

Guida contributor