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

Additional `List.intersperse` simplifications #142

Closed lue-bird closed 12 months ago

lue-bird commented 1 year ago

List.intersperse a [] --> [] already exist. Possible additions:

List.intersperse a [ b ]
--> [ b ]
-- which includes for example
List.intersperse a << List.singleton
--> List.singleton

List.intersperse a [ b, c ]
--> [ b, a, c ]

I imagine the last one is controversial because you sometimes expect to add more elements to the list in the future or just want make the separators the rule, like

[ navigationPanelUi
, channelMessagesUi
]
    |> List.intersperse (Ui.spacer 10)
-->
[ navigationPanelUi
, Ui.spacer 10
, channelMessagesUi
]

Since we also don't for example fix List.sum [ a, b ] to a + b it probably makes sense to not add this check to simplify (but to something like miniBill/elm-review-optimize)

jfmengels commented 12 months ago

I'm in favor of the former one, but as you suggested not in favor for the last one (where the element gets introduced) for the reasons you mentioned.