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

Simplify Dict.keys/values >> List.fold #308

Open jfmengels opened 2 months ago

jfmengels commented 2 months ago

Similar to changes like the one introduced in https://github.com/jfmengels/elm-review-simplify/pull/76, but for Dict.

The reason why we have this for Set and Array but not for Dict, is because the fold functions for Dict take an additional argument, which requires changes potentially far away. This is however easily resolvable when the fold function is an anonymous function:

When using Dict.keys:

dict
        |> Dict.keys
        |> List.foldl (\key acc -> ...) x
-->
dict
        |> Dict.foldl (\key _ acc -> ...) x

When using Dict.values:

dict
        |> Dict.values
        |> List.foldl (\value acc -> ...) x
-->
dict
        |> Dict.foldl (\_ value acc -> ...) x

(if List.foldr is used, then we would use Dict.foldr instead)