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 Task.sequence simplifications #166

Closed lue-bird closed 11 months ago

lue-bird commented 11 months ago

Implementation should also make it easy to extend to Maybe/Result/Random/Parser.Extra.sequence/combine in the future

Task.sequence [ Task.succeed a, Task.succeed b ]
--> Task.succeed [ a, b ]

Task.sequence [ Task.succeed a, Task.fail x ]
--> Task.fail x

Task.sequence [ task ]
--> Task.map List.singleton task

Task.sequence [ a, Task.fail x, b ]
--> Task.sequence [ a, Task.fail x ]

-- for example not in summary
Task.sequence << List.singleton
--> Task.map List.singleton

-- not in summary because theoretically same case as the first but with a separate error
Task.sequence []
--> Task.succeed []

Note that we do not simplify

Task.sequence [ task, Task.fail x ]
--> Task.fail x

because task could fail earlier. We also don't simplify it to

Task.sequence [ task, Task.fail x ]
--> Task.onError (always (Task.fail x)) task

because this is arguably a code style choice.

lue-bird commented 11 months ago

Setting to draft because I will also add

Task.sequence [ a, Task.fail x, b ]
--> Task.sequence [ a, Task.fail x ]