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 List.sum and List.product #127

Open lue-bird opened 1 year ago

lue-bird commented 1 year ago

when expectNaN is disabled

List.sum [ a, n, b, c - n ]
--> List.sum [ a, b, c ]

List.sum [ a, n, b, -n ]
--> List.sum [ a, b ]

List.sum [ a, n, b, c + (-n) ]
--> List.sum [ a, b, c ]

List.product [ a, 0, b ] ✅
--> 0

always

List.sum [ a, 0, b ] ✅
--> List.sum [ a, b ]

List.product [ a, 1, b ] ✅
--> List.product [ a, b ]
jfmengels commented 1 year ago

To add to the list:

When expectNaN is disabled

List.sum [ a, n, b, - n ]
--> List.sum [ a, b ]

List.product [ a, 0, b ]
--> 0
lue-bird commented 1 year ago
List.product [ a, 0, b ]
--> 0

was already in the list.

List.sum [ a, n, b, -n ]
--> List.sum [ a, b ]

in my mind was covered by

List.sum [ a, n, b, c + (-n) ]
--> List.sum [ a, b, c ]

but I added it to the issue description.