Skip to content

Commit f7dd1e5

Browse files
authored
Add back deleted examples
Removed as part of tc39/proposal-iterator-helpers#263
1 parent 5b62191 commit f7dd1e5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,38 @@ This proposal introduces two new intrisic objects, in addition to the two added
6060
const AsyncIteratorHelperPrototype = Object.getPrototypeOf(AsyncIterator.from([]).take(0));
6161
const WrapForValidAsyncIteratorPrototype = Object.getPrototypeOf(AsyncIterator.from({ async next(){} }));
6262
```
63+
64+
## More Example Usage
65+
66+
### Lazy Iteration over sets
67+
68+
Iterating over a set of URLs, asynchronously fetching each, and returning an array of their
69+
JSON Output.
70+
71+
```js
72+
const responses = await AsyncIterator.from(urls)
73+
.map(async (url) => {
74+
const response = await fetch(url);
75+
return response.json();
76+
})
77+
.toArray();
78+
```
79+
80+
Example of iterating over a potentially infinite iterator and transforming it to an array in groups
81+
of 5.
82+
83+
```js
84+
class ObligatoryCryptocurrencyReference extends Component {
85+
componentWillMount() {
86+
const items = ticker() // returns async iterator
87+
.map((c) => createElement('h2', null, `${c.name}: ${c.price}`))
88+
.take(5) // only consume 5 items of a potentially infinite iterator
89+
.toArray() // greedily transform async iterator into array
90+
.then((data) => this.setState({ data }));
91+
}
92+
93+
render() {
94+
return createElement('div', null, this.state.data);
95+
}
96+
}
97+
```

0 commit comments

Comments
 (0)