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

Simplify record field accesses #25

Open jfmengels opened 2 years ago

jfmengels commented 2 years ago

These are a bunch of simplifications related to field access that can be interesting to support.

DONE

{ unrelated = 1, field = someFn value }.field
--> (someFn value)

{ a | field = someFn value }.field
--> (someFn value)

{ a | unrelated = someFn value }.field
--> a.field

(\a -> { field = a }) >> .field
--> identity

/DONE

More complex:

value |> (\a -> { field = a }) |> .field
--> value

(Related discussion: #24)

miniBill commented 2 years ago

I think #35 and #37 solve the "simple" part. The "complex" part looks... intriguing but I wonder how often it happens?

jfmengels commented 2 years ago

The tool is meant to have your back, so it doesn't matter how often it happens :grin: I don't know if the code will be be re-usable (probably not) but there are already quite a few checks that support these function patterns.

But yeah, I'll mark the rest as completed. We can leave the complex part for whenever someone feels like it.