jfmengels / elm-review-simplify

Provides elm-review rules to simplify your Elm code
https://package.elm-lang.org/packages/jfmengels/elm-review-simplify/latest/
BSD 3-Clause "New" or "Revised" License
20 stars 9 forks source link

Add simplifications for Dict.toList, then List.map tuple part access #102

Closed lue-bird closed 1 year ago

lue-bird commented 1 year ago

As shown in the Dict section of https://github.com/jfmengels/elm-review-simplify/issues/2

List.map Tuple.first (Dict.toList dict)
--> Dict.keys dict
List.map Tuple.second (Dict.toList dict)
--> Dict.values dict

List.map (\( part0, _ ) -> part0) (Dict.toList dict)
--> Dict.keys dict
List.map (\( part1, _ ) -> part1) (Dict.toList dict)
--> Dict.values dict

List.map Tuple.first << Dict.toList
--> Dict.keys
List.map Tuple.second << Dict.toList
--> Dict.values

Only the first 2 are shown in the summary

What might be interesting to add is

List.map (Tuple.first >> f) (Dict.fromList dict)
--> List.map f (Dict.keys dict)
List.map (\( part0, _ ) -> f part0) (Dict.fromList dict)
--> List.map f (Dict.keys dict)

etc