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 Array.append simplifications #199

Closed jfmengels closed 11 months ago

jfmengels commented 11 months ago

Adds Array.append simplifications #174

I extracted listAppendChecks into a generic collectionAppendChecks. I noticed it got very close to collectionUnionChecks and changed the error messages to match collectionUnionChecks because they were nicer.

Now collectionAppendChecks and collectionUnionChecks are pretty much the same check, except that the former tries to combine append [ a ] [ b ] into [ a, b ].

I think we can make that work for dict/set as well in a next step, completely fusing the 2 collection checks. The only difference is that sets and dict need to have the elements added to the end rather than at the beginning, so union (fromList [ a ]) (fromList [ b ]) into fromList [ b, a ]. I'll do that in a follow-up PR.

Can be reviewed commit by commit.

github-actions[bot] commented 11 months ago

The branch can be tried out by running:

elm-review --template jfmengels/elm-review-simplify/preview
lue-bird commented 11 months ago

This has been on my wishlist for some time. Very cool! I love the FromListProperties.

lue-bird commented 11 months ago

I suspect there could be issues with cases like

Array.append ([ 1 ] |> Array.fromList) (Array.fromList [ 2 ])

Would be cool to add tests for these cases

jfmengels commented 11 months ago

I added more tests, it looks like things are working as expected :+1: