Closed jfmengels closed 11 months ago
Yeah, there's no smart mechanism to allow this. I'd just add a custom check.
I've been trying to simplify List.repeat 1
but I'm not sure about the simplifications outside of the simple List.repeat 1 x
case.
For instance, the following solution doesn't feel like an improvement (It's surprising how odd it feels to not have a Array.singleton
function...) :
List.repeat 1
--> List.singleton >> Array.fromList
Not sure what to do when seeing it in a pipeline either, like
x
|> f
|> Array.repeat 1
|> g
-->
[ x
|> f
]
|> Array.fromList
|> g
I'm thinking we should not replace List.repeat 1
, and maybe only do the simple List.repeat 1 x
and List.repeat 1 <| x
cases.
And yeah those Array.fromList singleton
cases all seem very ugly.
Might just be best to always leave Array.repeat 1
as is than to apply this fix so inconsistently.
Adds simplifications for
Array.repeat
#174Array.repeat 0 x
->Array.empty
Array.repeat -1 x
->Array.empty
I also wanted to do
but the existing checks (
wrapperRepeatChecks
) don't work for this type which doesn't have aArray.singleton
function. @lue-bird if you can think of an easy way to add this, let me know, otherwise I'll leave it for later and focus on other issues first :smile: