tc39 / proposal-flatMap

proposal for flatten and flatMap on arrays
https://tc39.github.io/proposal-flatMap
214 stars 19 forks source link

Replace spreadable with isArray #45

Closed jakearchibald closed 6 years ago

jakearchibald commented 6 years ago

Things like strings are spreadable, but IsArray(_element_) returns false for these. Other methods use isArray to store the return value of IsArray.

benlesh commented 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)

bakkot commented 6 years ago

@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.

michaelficarra commented 6 years ago

No thanks, I intentionally left this variable name. If you would want to rename it to flattenable, I may be okay with that.

jakearchibald commented 6 years ago

Why is isArray bad? Seems consistent with other specs.

michaelficarra commented 6 years ago

@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.