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

Add Json.decode.mapN simplifications #222

Closed lue-bird closed 1 year ago

lue-bird commented 1 year ago

Completes the Json.Decode simplifications listed in #2 and more.

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

Json.Decode.map3 f (Json.Decode.succeed a) (Json.Decode.fail x) thirdDecoder
--> Json.Decode.fail x

Json.Decode.map3 f firstDecoder (Json.Decode.fail x) thirdDecoder
--> Json.Decode.map2 f firstDecoder (Json.Decode.fail x)

Bonus: Make using mapN checks more concise by using argCount to infer the n

github-actions[bot] commented 1 year ago

The branch can be tried out by running:

elm-review --template jfmengels/elm-review-simplify/preview