Skip to content

Add back deleted examples #13

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,38 @@ This proposal introduces two new intrisic objects, in addition to the two added
const AsyncIteratorHelperPrototype = Object.getPrototypeOf(AsyncIterator.from([]).take(0));
const WrapForValidAsyncIteratorPrototype = Object.getPrototypeOf(AsyncIterator.from({ async next(){} }));
```

## 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);
}
}
```