jfmengels/elm-review-simplify

Remove duplicate entries in Set.fromList/Dict.fromList

Open

#326 创建于 2024年12月13日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)Elm (10 fork)github user discovery
enhancementhelp wanted

仓库指标

Star
 (22 star)
PR 合并指标
 (PR 指标待抓取)

描述

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 ]

贡献者指南