Skip to content

Commit

Permalink
improving docs, stopped at .reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
Keloo committed Aug 9, 2018
1 parent c0535f0 commit 06d018f
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,14 @@ If index is out of the range, returns `undefined` .
```ts
import { queryAsync } from 'itiriri-async';

queryAsync(['a', 'b', 'c', 'd']).nth(2) // returns 'c'
queryAsync(['a', 'b', 'c', 'd']).nth(-1) // returns 'd'
queryAsync(['a', 'b', 'c', 'd']).nth(10) // returns undefined
async function* generator() {
yield* [1, -2, 3];
}

(async function () {
await queryAsync(generator()).nth(2); // returns: 3
await queryAsync(generator()).nth(3); // returns: undefined
})();
```

### `prepend`
Expand All @@ -1008,7 +1013,10 @@ queryAsync(['a', 'b', 'c', 'd']).nth(10) // returns undefined
> Syntax
```ts
prepend(other: AsyncIterable<T> | T): AsyncIterableQuery<T>;
prepend(other: T): AsyncIterableQuery<T>;
prepend(other: Promise<T>): AsyncIterableQuery<T>;
prepend(other: Iterable<T>): AsyncIterableQuery<T>;
prepend(other: AsyncIterable<T>): AsyncIterableQuery<T>;
```

> Parameters
Expand All @@ -1019,7 +1027,19 @@ prepend(other: AsyncIterable<T> | T): AsyncIterableQuery<T>;
```ts
import { queryAsync } from 'itiriri-async';

queryAsync([1, 2, 3]).prepend([9, 10]).toArray(); // returns [1, 2, 3, 9, 10]
async function* generator() {
yield* [1, -2, 3];
}

(async function () {
const q = await queryAsync(generator()).prepend(4).awaitAll();
q.toArray(); // returns: [4, 1, -2, 3]
})();

(async function () {
const q = await queryAsync(generator()).prepend([0, 4]).awaitAll();
q.toArray(); // returns: [0, 4, 1, -2, 3]
})();
```

`prepend` *is a deferred method and is executed only when the result sequence is iterated.*
Expand Down

0 comments on commit 06d018f

Please sign in to comment.