Skip to content

Commit

Permalink
improving docs, stopped at nth
Browse files Browse the repository at this point in the history
  • Loading branch information
Keloo committed Aug 9, 2018
1 parent 558dd24 commit c0535f0
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -838,22 +838,16 @@ the `joinSelector` function is called with an `undefined` right value.
```ts
import { queryAsync } from 'itiriri-async';

queryAsync([1, 2, 3])
.leftJoin([2, 3, 4, 2], n => n, n => n, (a, b) => `${a}-${b || '#'}`)
.toArray();
// returns ['1-#', '2-2', '2-2', '3-3']

queryAsync([{book: 'History', owner: 3}, {book: 'Math', owner: 2}, {book: 'Art'}]])
.leftJoin(
[{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Eve'}],
left => left.owner,
right => right.id,
(left, right) => ({book: left.book, owner: right && right.owner || '--'}))
.toArray();
// returns [
// {book: 'History', owner: 'Eve'},
// {book: 'Math', owner: 'Bob'},
// {book: 'Art', owner: '--'}]
async function* generator() {
yield* [1, 2, 3];
}

(async function () {
const q = await queryAsync(generator())
.leftJoin([2, 3, 4, 2], n => n, n => n, (a, b) => `${a}-${b || '#'}`)
.awaitAll();
q.toArray(); // returns ['1-#', '2-2', '2-2', '3-3']
})();
```

`leftJoin` *is a deferred method and is executed only when the result sequence is iterated.*
Expand All @@ -877,8 +871,13 @@ length(predicate: (element: T, index: number) => boolean): <number>;
```ts
import { queryAsync } from 'itiriri-async';

queryAsync([1, 2, 3, 4, 5]).length(); // returns 5
queryAsync([1, 2, 3, 4, 5]).length(elem => elem > 2); // returns 3
async function* generator() {
yield* [1, 2, 3];
}

(async function () {
await queryAsync(generator()).length(); // return: 3
})();
```

### `map`
Expand Down Expand Up @@ -928,9 +927,14 @@ If sequence is empty, returns `undefined`.
```ts
import { queryAsync } from 'itiriri-async';

queryAsync([1, 2, 3]).max(); // returns 3
queryAsync([]).max(); // returns undefined
queryAsync([7, 3, 11, 5]).max((a, b) => (1 / a) - (1 / b)); // returns 3
async function* generator() {
yield* [1, 2, 3];
}

(async function () {
const q = await queryAsync(generator()).map(x => x * 10).awaitAll();
q.toArray(); // returns [10, 20, 30]
})();
```

### `min`
Expand All @@ -957,9 +961,19 @@ If sequence is empty, returns `undefined`.
```ts
import { queryAsync } from 'itiriri-async';

queryAsync([1, 2, 3]).min(); // returns 1
queryAsync([]).min(); // returns undefined
queryAsync([7, 3, 11, 5]).min((a, b) => (1 / a) - (1 / b)); // returns 11
async function* generator1() {
yield* [1, -2, 3];
}

async function* generator2() {
yield* [];
}


(async function () {
await queryAsync(generator1()).min(); // returns -1
await queryAsync(generator2()).min(); // returns undefined
})();
```

### `nth`
Expand All @@ -975,7 +989,6 @@ nth(index: number): Promise<T>;
> Parameters
* `index` - *(required)* zero based index at which to get the element

For a negative index returns the element from the end of the sequence.
If index is out of the range, returns `undefined` .

> Example
Expand Down Expand Up @@ -1060,7 +1073,6 @@ skip(count: number): AsyncIterableQuery<T>;
* `count` - *(required)* number of elements to skip

When *count* is greater than actual number of elements, results in an empty sequence.
Accepts also a negative count, in which case skips the elements from the end of the sequence.

> Example
Expand Down Expand Up @@ -1160,8 +1172,6 @@ take(count: number): AsyncIterableQuery<T>;
> Parameters
* `count` - *(required)* number of elements to take

If a negative count is specified, returns elements from the end of the sequence.

> Example
```ts
Expand Down

0 comments on commit c0535f0

Please sign in to comment.