underscore
underscore copied to clipboard
iterator support for _.toArray
I think support for converting iterators to arrays would be a nice to have for _.toArray
.
@jdalton Do you mean Array.from ? I think, it is should be like polyfill Array.from
Do you mean Array.from ?
I mean something like iteratorToArray which can be used as part of toArray.
Browsers like IE11 have support for Map
and Set
without support for Array.from
.
I think, it is should be like polyfill Array.from
Ya I get that, but _.toArray
has more features. The addition of iterator support would round it out.
Array.from({ 'a': 1 })
// => []
_.toArray({ 'a': 1 })
// => [1]
Rather than reimplementing toArray
why don't we just call Array.from
if it exists? You probably wouldn't / shouldn't be using iterators if you haven't polyfilled Array.from
.
You probably wouldn't / shouldn't be using iterators if you haven't polyfilled
Array.from
.
Because Array.from
isn't a requirement for iterator conversion and there are environments without it where maps and sets and other iterables work fine. So it would be inconsistent support.
The lines savings aren't worth the inconsistent support. We're talking about 4 or 5 LOC (less than 100 bytes). Nothing major.
Will only make sense if combined with #2147.