Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: either support arbitrary iterables in std/collections or split into std/array / std/record(?) #4671

Open
Jessidhia opened this issue May 2, 2024 · 3 comments
Labels
suggestion a suggestion yet to be agreed

Comments

@Jessidhia
Copy link

Jessidhia commented May 2, 2024

std/collections has a very... ambitious name for the kind of things it can operate on: either native arrays or property bag objects ("Record" in TypeScript parlance); I actually found this genuinely a bit surprising while browsing the API.

It should be possible to get support for any non-Array @@iterator (such as TypedArray, NodeList, HTMLCollection, Set, generator call result, etc) for free on functions that don't do random access by operating on Iterable<T> instead of readonly T[] arguments.

Similarly, the functions that operate on records can also support Map (and URLSearchParams, and other Map-likes) by accepting an Iterable<[K, T]> / Iterable<[K, Iterable<T>]> / etc, and using Object.entries to convert non-iterable records to an iterable version.


If this is genuinely beyond the scope of what you want in a module named @std/collections, then perhaps it should be split/renamed to something more specific, or alternatively specialized implementations that don't go through the iterator protocol could, e.g., be published in an @std/array

@Jessidhia Jessidhia added bug Something isn't working needs triage labels May 2, 2024
@kt3k kt3k added suggestion a suggestion yet to be agreed and removed bug Something isn't working needs triage labels May 2, 2024
@Jessidhia
Copy link
Author

(Embarrassingly, it turns out I just happened to only have clicked on the exports that did not support Iterables like chunk, takeWhile, unzip; another handful of the exports do support Iterables, so I suppose this is already in progress?)

@kt3k
Copy link
Member

kt3k commented May 6, 2024

Yes, we've been gradually adding support of iterables where they make sense (such as #3390 ). PRs are welcome if you find more places suitable for supporting it.

@iuioiua
Copy link
Collaborator

iuioiua commented May 6, 2024

Can we open a tracking issue for the remaining work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion a suggestion yet to be agreed
Projects
None yet
Development

No branches or pull requests

3 participants