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

split async helpers into their own repo #263

Merged
merged 2 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 4 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Champions: Michael Ficarra, Yulia Startsev

This proposal is at Stage 3 of [The TC39 Process](https://tc39.es/process-document/).

This proposal formerly contained async as well as sync helpers. The async helpers have been split out to [a seperate proposal](https://github.com/tc39/proposal-async-iterator-helpers).

## Motivation

Iterators are a useful way to represent large or possibly infinite enumerable data sets. However,
Expand All @@ -20,17 +22,15 @@ or using libraries to introduce the necessary helpers. Many [libraries and langu

## Proposal

The proposal introduces a collection of new methods on the Iterator and AsyncIterator prototypes, to allow general
usage and consumption of iterators. For specifics on the implemented methods, please refer to the
specification.
The proposal introduces a collection of new methods on the Iterator prototype, to allow general usage and consumption of iterators. For specifics on the implemented methods, please refer to the specification.

See [DETAILS.md](./DETAILS.md) for details on semantics decisions.

See this proposal rendered [here](https://tc39.es/proposal-iterator-helpers)

## Added Methods

For Iterators and AsyncIterators we add the following methods:
For Iterators we add the following methods:

### `.map(mapperFn)`

Expand Down Expand Up @@ -328,40 +328,6 @@ use the remainder of the generator protocol. Specifically, such iterators do
not implement `.throw` and do not forward the parameter of `.next` or `.return`
to an underlying or "source" iterator.

## More Example Usage

### Lazy Iteration over sets

Iterating over a set of URLs, asynchronously fetching each, and returning an array of their
JSON Output.

```js
const responses = await AsyncIterator.from(urls)
.map(async (url) => {
const response = await fetch(url);
return response.json();
})
.toArray();
```

Example of iterating over a potentially infinite iterator and transforming it to an array in groups
of 5.

```js
class ObligatoryCryptocurrencyReference extends Component {
componentWillMount() {
const items = ticker() // returns async iterator
.map((c) => createElement('h2', null, `${c.name}: ${c.price}`))
.take(5) // only consume 5 items of a potentially infinite iterator
.toArray() // greedily transform async iterator into array
.then((data) => this.setState({ data }));
}

render() {
return createElement('div', null, this.state.data);
}
}
```

#### Extending Iterator Prototype

Expand Down Expand Up @@ -406,9 +372,7 @@ any form of iterator, different iterators have to be handled differently.

```js
const IteratorHelperPrototype = Object.getPrototypeOf(Iterator.from([]).take(0));
const AsyncIteratorHelperPrototype = Object.getPrototypeOf(AsyncIterator.from([]).take(0));
const WrapForValidIteratorPrototype = Object.getPrototypeOf(Iterator.from({ next(){} }));
const WrapForValidAsyncIteratorPrototype = Object.getPrototypeOf(AsyncIterator.from({ async next(){} }));
```

## Prior Art & Userland implementations
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"private": true,
"scripts": {
"build": "mkdir -p dist && ecmarkup --lint-spec --strict --load-biblio @tc39/ecma262-biblio --verbose --js-out dist/ecmarkup.js --css-out dist/ecmarkup.css spec.html dist/index.html",
"build-biblio": "ecmarkup --write-biblio proposal-iterator-helpers-biblio.json --lint-spec --strict --load-biblio @tc39/ecma262-biblio --verbose spec.html /dev/null",
"format": "emu-format --write spec.html",
"check-format": "emu-format --check spec.html"
},
Expand Down
Loading