Skip to content

Commit 5c03584

Browse files
committed
docs: Improve docs for createIterable and getIterator utilities
1 parent 8c02d7b commit 5c03584

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

docs/utils/iterable.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,35 @@ title: Iterable Utilities
1515

1616
Makes an `Iterable` from a provided function. It could be a generator or a factory, but must return a new `Iterator` every time.
1717

18+
```js
19+
const iterable = createIterable(function* () {
20+
while (true) yield Math.random();
21+
});
22+
23+
const [x, y] = iterable;
24+
const [z] = iterable;
25+
26+
// x === 0.6486486024235587
27+
// y === 0.3952175724953333
28+
// z === 0.8863071830215743
29+
```
30+
1831
### getIterator
1932

2033
`getIterator(iterable) => Iterator`
2134

2235
Calls the `Symbol.iterator` method of the `iterable` for you.
2336

37+
```js
38+
const iterator = getIterator(`undercut`);
39+
40+
// Iterator {}
41+
42+
iterator.next();
43+
44+
// {value: "u", done: false}
45+
```
46+
2447
### getRecursiveMapper
2548

2649
`getRecursiveMapper(predicate, mapper) => Mapper`

0 commit comments

Comments
 (0)