You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
Array.from supports non-iterable “arraylike” objects: objects that have integer properties and a length property but no Symbol.iterator property. For example, Array.from({ 0: 'a', 1: 'b', 2: 'c', length: 2 }) returns [ 'a', 'b' ].
Array.fromAsync is also going to support non-iterable “arraylike” objects. For example, await Array.fromAsync({ 0: Promise.resolve('a'), 1: Promise.resolve('b'), 2: Promise.resolve('c'), length: 2 }) returns [ 'a', 'b' ].
Array.fromAsync(input) is designed to be equivalent to AsyncIterator.from(input).toArray().
This comes from how Array.from(input) would be equivalent to Iterator.from(input).toArray().
However, they are not actually equivalent, because Iterator.from(input) and AsyncIterator.from(input) do not support non-iterable arraylike inputs. Should they? (I don’t have a strong opinion except that an explicit decision should be made.)
The text was updated successfully, but these errors were encountered:
No, they should not. Array.from (and I guess its async version) should be the one and only way of consuming arraylikes. It's fine for Array.fromAsync and AsyncIterator.from(input).toArray() to differ in this way.
Array.from supports non-iterable “arraylike” objects: objects that have integer properties and a length property but no Symbol.iterator property. For example,
Array.from({ 0: 'a', 1: 'b', 2: 'c', length: 2 })
returns[ 'a', 'b' ]
.Array.fromAsync is also going to support non-iterable “arraylike” objects. For example,
await Array.fromAsync({ 0: Promise.resolve('a'), 1: Promise.resolve('b'), 2: Promise.resolve('c'), length: 2 })
returns[ 'a', 'b' ]
.Array.fromAsync(input)
is designed to be equivalent toAsyncIterator.from(input).toArray()
.This comes from how
Array.from(input)
would be equivalent toIterator.from(input).toArray()
.However, they are not actually equivalent, because
Iterator.from(input)
andAsyncIterator.from(input)
do not support non-iterable arraylikeinput
s. Should they? (I don’t have a strong opinion except that an explicit decision should be made.)The text was updated successfully, but these errors were encountered: