Open NV opened 10 years ago
Yes, the expected output is [1, 2]
.
@NV Do you expect flatten to be recursive/transitive deepFlatten, as in [[[1, 2], 3, [[[4]]]]]
to be [1, 2, 3, 4]
?
I originally expected it to be recursive/transitive deepFlatten, but now I’m thinking there might be a use case for shallow flatten as well.
Shallow is certainly the behavior of the corresponding FRB operator. There are cases like concatenating map entries, [[key, value], [key, value]]
or concatenating tables that would not work out.
I could add deepFlatten. I think the existence of an iterate
method would suffice in distinguishing iterables from non-flattenable values.
Where
work
means return[1, 2]
, treating1
as[1]
since, since it is not Array.isArray? Array.isArray would be trouble because[Set([1]), Set([2])]
should return[1, 2]
, not[[Set(1)], [Set([2])]]
. Perhaps a duck test instead. I’ll try to stifle my impulse to drop the issue from the ivory tower of type purity :wink: