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.mapN simplifications #180

Closed lue-bird closed 11 months ago

lue-bird commented 11 months ago

Just like #173

-- the following simplifications for map3 work for all Task.mapN
Task.map3 f (Task.succeed a) (Task.succeed b) (Task.succeed c)
--> Task.succeed (f a b c)

Task.map3 f (Task.succeed a) (Task.fail x) thirdTask
--> Task.fail x

Task.map3 f firstTask (Task.fail x) thirdTask
--> Task.map2 f firstTask (Task.fail x)
jfmengels commented 11 months ago

I was really unsure about removing tasks but TIL

Say we were doing HTTP requests instead. map2 does each task in order, so it would try the first request and only continue after it succeeds. If it fails, the whole thing fails!