Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Iterator.from: Accept non-iterable array-like inputs? #155

Closed
js-choi opened this issue Sep 15, 2021 · 6 comments
Closed

Iterator.from: Accept non-iterable array-like inputs? #155

js-choi opened this issue Sep 15, 2021 · 6 comments

Comments

@js-choi
Copy link

js-choi commented Sep 15, 2021

Spinning this off of tc39/proposal-array-from-async#7.

Iterator.from and AsyncIterator.from were inspired by Array.from.

Array.from accepts not only iterable inputs. It also accepts non-iterable array-like inputs.

Should Iterator.from and AsyncIterator.from match Array.from and also accept non-iterable array-like inputs?

CC: @codehag, @michaelficarra, @ljharb.

#156 is slightly related to this.

@ljharb
Copy link
Member

ljharb commented Sep 15, 2021

Yes, I think they should.

@zloirock
Copy link
Contributor

Non-iterables are handled in Iterator.from as iterators and wrapped to a proxy iterator. Too many protocols for one method.

@ljharb
Copy link
Member

ljharb commented Sep 15, 2021

The entire point of a .from method is to accept everything possible and output a "good" result.

@michaelficarra
Copy link
Member

I think the question is confused? Iterator.from and AsyncIterator.from accept iterators, not (necessarily) iterables. I don't see the parallel with Array.from or your new async variant with regards to array-likes.

@ljharb
Copy link
Member

ljharb commented Sep 15, 2021

ha, you're right, my bad - too many issues asking this same question :-). Iterator.from already takes iterator-likes, so it seems fine as-is.

@js-choi
Copy link
Author

js-choi commented Sep 15, 2021

Yeah, you are right! I was a bit confused.

@js-choi js-choi closed this as completed Sep 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants