Skip to content

bakkot/proposal-iterator-join

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 0 of the TC39 process: it has not yet been presented to the committee.

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published