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

Apply simplifications for ++ when encountering List.singleton #149

Closed jfmengels closed 12 months ago

jfmengels commented 12 months ago

Currently, the following simplification is applied:

[ 1 ] ++ [ 2 ]
--> [ 1, 2 ]

and there are more and more checks where we consider [ 1 ] the same as List.singleton 1. But we don't support the following simplification:

List.singleton 1 ++ [ 2 ]
--> [ 1, 2 ]

[ 1 ] ++ List.singleton 2
--> [ 1, 2 ]

I guess we could also do

List.singleton 1 ++ List.singleton 2
--> [ 1, 2 ]

but I could understand some push-back on that.

jfmengels commented 12 months ago

Nevermind, I was comparing with older versions and got confused. All of my examples get fixed. For instance, List.singleton 1 ++ List.singleton 2 gets fixed to 1 :: List.singleton 2.

One thing that feels missing though and I'm thinking we should push it further is 1 :: List.singleton 2 should probably be fixed to [ 1, 2 ], as that is a lot more idiomatic Elm code.