tc39 / proposal-flatMap

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

Get "length" performed after ArraySpeciesCreate #1

Closed zenparsing closed 7 years ago

zenparsing commented 8 years ago

For the existing array methods, we get the "length" property of the source (which could fail) before creating the target array. Should it work the same here?

bterlson commented 8 years ago

It seems of minor importance that it work the same. I couldn't figure a clean way to do it with the factoring I have now.

bterlson commented 8 years ago

I can do this by having FlattenIntoArray create an array if one isn't passed into it, but then it would have to return an array or next index, or a tuple of both. Who can think of a better way? :-P

ljharb commented 8 years ago

In both of the places you're calling FlattenIntoArray, you're just creating the array at the outset. What if FlattenIntoArray took O and len, and created/returned the new array itself?