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
19 stars 9 forks source link

operations with NaN #258

Open lue-bird opened 12 months ago

lue-bird commented 12 months ago

when expectNaN is enabled

-- also works when NaN is on the other side
(0 / 0) + n --> 0 / 0
(0 / 0) - n --> 0 / 0
(0 / 0) * n --> 0 / 0
(0 / 0) / n --> 0 / 0

List.product and List.sum were implemented in #257

If you think there are more, comment or edit this issue.

Edit: thanks to Simon Lydell on slack for finding out that these ↓ only sometimes return NaN:

Basics.max (0 / 0) n --> ❌ 0 / 0
Basics.min (0 / 0) n --> ❌ 0 / 0
List.maximum [ a, 0 / 0, b ] --> ❌ Just (0 / 0)
List.minimum [ a, 0 / 0, b ] --> ❌ Just (0 / 0)

The edge cases:


Basics.min (0 / 0) 5 --> 5
Basics.min 5 (0 / 0) --> 0 / 0

Basics.max (0 / 0) 5 --> 0 / 0 Basics.max 5 (0 / 0) --> 5

List.minimum [ 0 / 0, 5 ] --> Just ( 0 / 0) List.minimum [ 5, 0 / 0 ] --> Just 5

List.maximum [ 0 / 0, 5 ] --> Just 5 List.maximum [ 5, 0 / 0 ] --> Just (0 / 0)