Closed jfmengels closed 11 months ago
The branch can be tried out by running:
elm-review --template jfmengels/elm-review-simplify/preview
This has been on my wishlist for some time. Very cool! I love the FromListProperties
.
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
I added more tests, it looks like things are working as expected :+1:
Adds Array.append simplifications #174
Array.append Array.empty array
->array
Array.append array Array.empty
->array
Array.append (Array.fromList [ a, b, c ]) (Array.fromList [ d, e, f ])
->Array.fromList [ a, b, c, d, e, f ]
I extracted
listAppendChecks
into a genericcollectionAppendChecks
. I noticed it got very close tocollectionUnionChecks
and changed the error messages to matchcollectionUnionChecks
because they were nicer.Now
collectionAppendChecks
andcollectionUnionChecks
are pretty much the same check, except that the former tries to combineappend [ 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 ])
intofromList [ b, a ]
. I'll do that in a follow-up PR.Can be reviewed commit by commit.