Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

tc39/proposal-iterator-join

Open more actions menu

Iterator Join

A proposal to add to JavaScript a means to concatenate the contents of an iterator into a string.

Status

Authors: Kevin Gibbons

Champions: Kevin Gibbons

This proposal is at stage 2.7 of the TC39 process: it awaits Test262 tests. Tests have been written and now need review, at which point the proposal will be ready for stage 3.

Motivation

Joining a list of strings into a single string for display or other reasons is a very common operation. If you have an array, it's trivial: just call .join(sep). If you have any other iterable, you can either do Iterator.from(it).reduce((a, b) => a + sep + b) (and pay the cost of allocating all the intermediate strings, plus this breaks on empty iterators), or Array.from(it).join(sep) (and pay the cost of converting the whole thing to an Array).

We should make that easier.

This came up during the original iterator helpers proposal and later on the Discourse.

Proposal

While in principle there are various ways to solve this problem, the obvious one is to add Iterator.prototype.join which works exactly like Array.prototype.join except that it operates on its receiver as an iterator rather than as an Array. That is what is currently specified.

About

JS proposal for a means to concatenate the contents of an iterator into a string

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.