Closed jakearchibald closed 6 years ago
FWiW: flatMap
becomes a lot more powerful and ergonomic if it can take any "like" thing. Strings might not feel like a fit, but what about arguments
or other ArrayLike things?
In Rx we accept Observables, Promises, Arrays, Iterables, ArrayLikes, and (soon) AsyncIterables in flatMap. Very nice ergonomics, no known issues.
Perhaps flatMap could work on anything that Array.from
works on? (Maybe it already does in this proposal, and I'm just not aware)
@benlesh we've discussed this at some length already, here and in committee; see #8 and #34. A major point of concern is that most people do not seem to expect [['abc']].flatten()
to return ['a', 'b', 'c']
, and so it can't operate on array-likes; also, the thought was that it makes sense to stick to Arrays
given that we're spec'ing Array.prototype.flatten/flatMap
and not %IteratorPrototype%.flatMap
.
No thanks, I intentionally left this variable name. If you would want to rename it to flattenable
, I may be okay with that.
Why is isArray
bad? Seems consistent with other specs.
@jakearchibald In this context, we care only that it is something that we are going to flatten ("spread") into the containing array. That it was determined by IsArray
or some other abstract operation is not meaningful at that point.
Things like strings are spreadable, but
IsArray(_element_)
returns false for these. Other methods useisArray
to store the return value ofIsArray
.