Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/labs42io/itiriri-async
A library for asynchronous iteration.
https://github.com/labs42io/itiriri-async
async-await async-iterable async-iterator filter for-await-of map slice
Last synced: about 2 months ago
JSON representation
A library for asynchronous iteration.
- Host: GitHub
- URL: https://github.com/labs42io/itiriri-async
- Owner: labs42io
- License: mit
- Created: 2018-08-08T05:25:39.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-17T07:14:51.000Z (over 5 years ago)
- Last Synced: 2024-10-07T21:06:59.626Z (3 months ago)
- Topics: async-await, async-iterable, async-iterator, filter, for-await-of, map, slice
- Language: TypeScript
- Homepage: https://labs42io.github.io/itiriri-async
- Size: 105 KB
- Stars: 78
- Watchers: 7
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - itiriri-async
README
# itiriri-async
[![Build Status](https://travis-ci.org/labs42io/itiriri-async.svg)](https://travis-ci.org/labs42io/itiriri-async)
[![Coverage Status](https://coveralls.io/repos/github/labs42io/itiriri-async/badge.svg)](https://coveralls.io/github/labs42io/itiriri-async)Next generation library to manipulate [asynchronous iterators](https://github.com/tc39/proposal-async-iteration).
```ts
import * as WebRequest from 'web-request';
import itiririAsync from 'itiriri-async';type ToDo = {
id: number,
userId: number,
title: string,
completed: boolean,
};async function* todosAsync() {
let id = 1;
while (true) {
yield await WebRequest.json(`https://jsonplaceholder.typicode.com/todos/${id++}`);
}
}async function showTop2ToDos(): Promise {
const todos = await itiririAsync(todosAsync())
.filter(x => !x.completed)
.take(2)
.awaitAll();console.log(todos.toArray());
}showTop2ToDos();
// [ 'delectus aut autem', 'quis ut nam facilis et officia qui' ]
```> Check examples folder for more
## Installation
Using npm:
```javascript
$ npm install 'itiriri-async' --save
```Importing:
```javascript
import itiririAsync from 'itiriri-async';
```## Running tests
```javascript
$ npm install
$ npm test
```---
## Complete list of methods
* [average](#average)
* [awaitAll](#awaitall)
* [concat](#concat)
* [distinct](#distinct)
* [entries](#entries)
* [every](#every)
* [exclude](#exclude)
* [filter](#filter)
* [find](#find)
* [findIndex](#findindex)
* [findLast](#findlast)
* [findLastIndex](#findlastindex)
* [first](#first)
* [flat](#flat)
* [forEach](#foreach)
* [groupJoin](#groupjoin)
* [includes](#includes)
* [indexOf](#indexof)
* [intersect](#intersect)
* [join](#join)
* [keys](#keys)
* [last](#last)
* [lastIndexOf](#lastindexof)
* [leftJoin](#leftjoin)
* [length](#length)
* [map](#map)
* [max](#max)
* [min](#min)
* [nth](#nth)
* [prepend](#prepend)
* [reduce](#reduce)
* [skip](#skip)
* [slice](#slice)
* [some](#some)
* [sum](#sum)
* [take](#take)
* [union](#union)
* [values](#values)### `average`
Returns the average value.
> Syntax
```ts
average(): Promise;
average(selector: (element: T, index: number) => number): Promise;
```> Parameters
* `selector` - *(optional)* a value transformer function to apply to each elementFor a sequence with no elements returns `undefined`.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator1() {
yield* [41, 42, 43];
}async function* generator2() {
yield* [{value: 1}, {value: 2}];
}itiririAsync(generator1()).average() // returns Promise<42>
itiririAsync(generator2()).average(elem => elem.value) // returns Promise<1.5>
```### `awaitAll`
Awaits for all elements an returns `IterableQuery`.
The ruterned iterable is a sync [`itiriri`](https://npmjs.com/package/itiriri) iterable.> Syntax
```ts
awaitAll(): Promise>
```> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [41, 40, 43];
}// ...
const numbers = await itiririAsync(generator()).awaitAll();
// returns IterableQuery([41, 40, 43])numbers.sort().toArray();
// returns: [40, 41, 43]
```### `concat`
Concatenates the sequence with another one.
> Syntax
```ts
concat(other: T): AsyncIterableQuery;
concat(other: Promise): AsyncIterableQuery;
concat(other: Iterable): AsyncIterableQuery;
concat(other: AsyncIterable): AsyncIterableQuery;
```> Parameters
* `other` - *(required)* sequence to concatenate> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator1() {
yield* [1, 2, 3];
}async function* generator2() {
yield* [4, 5];
}(async function() {
const q = await itiririAsync(generator1()).concat(generator2()).awaitAll();
q.toArray(); // returns [1, 2, 3, 4, 5]
})();(async function() {
const q = await itiririAsync(generator1()).concat([2, 1]).awaitAll();
q.toArray(); // returns [1, 2, 3, 2, 1]
})();(async function() {
const q = await itiririAsync(generator1()).concat(-1).awaitAll();
q.toArray(); // returns [1, 2, 3, -1]
})();
````concat` *is a deferred method and is executed only when the result sequence is iterated.*
### `distinct`
Returns a sequence of unique elements.
> Syntax
```ts
distinct(): AsyncIterableQuery;
distinct(selector: (element: T) => S): AsyncIterableQuery;
```> Parameters
* `selector` - *(optional)* a value transformer function to be used for comparisons> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3, 3, 3, 4, 2];
}(async function () {
const q = await itiririAsync(generator()).distinct().awaitAll();
q.toArray(); // returns [1, 2, 3, 4]
})();
````distinct` *is a deferred method and is executed only when the result sequence is iterated.*
### `entries`
Returns a sequence of key/value pair for each element and its index.
> Syntax
```ts
entries(): AsyncIterableQuery<[number, T]>;
```> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* ['Bob', 'Alice'];
}(async function () {
const q = await itiririAsync(generator()).entries().awaitAll();
q.toArray(); // returns [[0, 'Bob'], [1, 'Alice']]
})();
````entries` *is a deferred method and is executed only when the result sequence is iterated.*
### `every`
Tests whether all the elements pass the predicate.
> Syntax
```ts
every(predicate: (element: T, index: number) => boolean): Promise;
```> Parameters
* `predicate` - *(required)* function to test for each element> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 4, 3, 0];
}(async function () {
await itiririAsync(generator()).every(x => x >= 0); // true
})();(async function () {
await itiririAsync(generator()).every(x => x > 0); // false
})();
```### `exclude`
Returns a sequence of elements not contained in a given sequence.
> Syntax
```ts
exclude(others: Iterable): AsyncIterableQuery;
exclude(others: Iterable, selector: (element: T) => S): AsyncIterableQuery;
```> Parameters
* `others` - *(required)* a sequence of elements to be excluded
* `selector` - *(optional)* a value transformer function to be used for comparisons> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator1() {
yield* [2, 0, 1, 8, 2];
}async function* generator2() {
yield* [{ id: 1 }, { id: 2 }];
}(async function () {
const q = await itiririAsync(generator1()).exclude([0, 1]).awaitAll();
q.toArray(); // returns [2, 8, 2]
})();(async function () {
const q = await itiririAsync(generator2()).exclude([{ id: 2 }], x => x.id).awaitAll();
q.toArray(); // returns [{id: 1}]
})();
````exclude` *is a deferred method and is executed only when the result sequence is iterated.*
### `filter`
Returns a sequence of elements that pass the predicate.
> Syntax
```ts
filter(predicate: (element: T, index: number) => boolean): AsyncIterableQuery;
```> Parameters
* `predicate` - *(required)* function to test for each element> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3, 4, 5];
}(async function () {
const q = await itiririAsync(generator()).filter(elem => elem < 3).awaitAll();
q.toArray(); // returns [1, 2]
})();(async function () {
const q = await itiririAsync(generator()).filter(elem => elem > 10).awaitAll();
q.toArray(); // returns []
})();
````filter` *is a deferred method and is executed only when the result sequence is iterated.*
### `find`
Finds the first element that satisfies the specified predicate.
> Syntax
```ts
find(predicate: (element: T, index: number) => boolean): Promise;
```> Parameters
* `predicate` - *(required)* function to test for each elementIf no element satisfies the predicate, returns `undefined`.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3, 4, 5];
}(async function () {
await itiririAsync(generator()).find(elem => elem > 2); // returns 3
})();(async function () {
await itiririAsync(generator()).find(elem => elem > 10); // returns undefined
})();
```### `findIndex`
Finds the first index at which a given element satisfies the specified predicate.
> Syntax
```ts
findIndex(predicate: (element: T, index: number) => boolean): Promise;
```> Parameters
* `predicate` - *(required)* function to test for each elementIf no element satisfies the predicate, returns `-1`.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3, 4, 5];
}(async function () {
await itiririAsync(generator()).find(elem => elem > 2); // returns 2
})();(async function () {
await itiririAsync(generator()).find(elem => elem > 10); // returns -1
})();
```### `findLast`
Finds the last element that satisfies the specified predicate.
> Syntax
```ts
findLast(predicate: (element: T, index: number) => boolean): Promise;
```> Parameters
* `predicate` - *(required)* function to test for each elementIf no element satisfies the predicate, returns `undefined`.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3, 4, 5];
}(async function () {
await itiririAsync(generator()).findLast(elem => elem > 2); // returns 5
})();(async function () {
await itiririAsync(generator()).findLast(elem => elem > 10); // returns undefined
})();
```### `findLastIndex`
Finds the last index at which a given element satisfies the specified predicate.
> Syntax
```ts
findLastIndex(predicate: (element: T, index: number) => boolean): Promise;
```> Parameters
* `predicate` - *(required)* function to test for each elementIf not present, returns `-1`.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3, 4, 5];
}(async function () {
await itiririAsync(generator()).findLastIndex(elem => elem > 2); // returns 4
})();(async function () {
await itiririAsync(generator()).findLastIndex(elem => elem > 10); // returns -1
})();
```### `first`
Returns the first element in a sequence.
> Syntax
```ts
first(): Promise;
```For an empty sequence returns `undefined`.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator1() {
yield* [1, 2, 3, 4, 5];
}async function* generator2() {
yield* [];
}(async function () {
await itiririAsync(generator1()).first(); // returns 1
})();(async function () {
await itiririAsync(generator2()).first(); // returns undefined
})();
```### `flat`
Returns a sequence with all sub-sequences concatenated.
> Syntax
```ts
flat(selector?: (element: T, index: number) => AsyncIterable): AsyncIterableQuery;
```> Parameters
* `selector` - *(optional)* a value transformer function to be used for comparisons> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [[1, 2, 3], [4, 5]];
}(async function () {
const q = await itiririAsync(generator()).flat().awaitAll();
q.toArray(); // returns [1, 2, 3, 4, 5]
})();
````flat` *is a deferred method and is executed only when the result sequence is iterated.*
### `forEach`
Runs through every element and applies a given function.
> Syntax
```ts
forEach(action: (element: T, index: number) => void): Promise;
```> Parameters
* `action` - *(required)* function to apply on each element> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}(async function () {
await itiririAsync(generator()).forEach(elem => console.log(elem));
})();
// 1
// 2
// 3
```### `groupJoin`
Returns a sequence of correlated elements where each element from the current sequence
is matched with zero or more elements from the other sequence.> Syntax
```ts
groupJoin(
other: Iterable,
leftKeySelector: (element: T, index: number) => TKey,
rightKeySelector: (element: TRight, index: number) => TKey,
joinSelector: (left: T, right: TRight[]) => TResult,
): AsyncIterableQuery;
```> Parameters
* `other` - *(required)* sequence to join
* `leftKeySelector` - *(required)* function that provides the key of each element from source sequence
* `rightKeySelector` - *(required)* function that provides the key of each element from joined sequence
* `joinSelector` - *(required)* a transformation function to apply on each joined element with groupThe `joinSelector` function is called on each element from the source sequence and the array of matched
elements from the joined sequence.
When an element from the source sequence doesn't match with any of the elements from the joined sequence,
the `joinSelector` function will be called with an empty array.> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}(async function () {
const q = await itiririAsync(generator())
.groupJoin([1, 2, 3, 1, 1, 2], x => x, x => x, (x, y) => ({ x, y }))
.awaitAll();
q.toArray();
})();
//[ { x: 1, y: [ 1, 1, 1 ] },
// { x: 2, y: [ 2, 2 ] },
// { x: 3, y: [ 3 ] } ]
````groupJoin` *is a deferred method and is executed only when the result sequence is iterated.*
### `includes`
Determines whether the sequence includes a certain element.
> Syntax
```ts
includes(element: T): Promise;
includes(element: T, fromIndex: number): Promise;
```> Parameters
* `element` - *(required)* the element to search for
* `fromIndex` - *(optional)* starting index, defaults to `0``includes` uses triple equals `===` to compare elements.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}(async function () {
await itiririAsync(generator()).includes(2); // returns: true
await itiririAsync(generator()).includes(4); // returns: false
})();
```### `indexOf`
Returns the first (zero-based) index at which a given element can be found.
> Syntax
```ts
indexOf(element: T): Promise;
indexOf(element: T, fromIndex: number): Promise;
```> Parameters
* `element` - *(required)* the element to search for
* `fromIndex` - *(optional)* starting index, defaults to `0`When an element is not found, returns -1.
`indexOf` uses triple equals `===` to compare elements.> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}(async function () {
await itiririAsync(generator()).indexOf(2); // returns: 1
await itiririAsync(generator()).indexOf(4); // returns: -1
})();
```### `intersect`
Returns a set intersection with a given sequence.
> Syntax
```ts
intersect(others: Iterable): AsyncIterableQuery;
intersect(other: Iterable, selector: (element: T) => S): AsyncIterableQuery;
```> Parameters
* `other` - *(required)* the sequence to intersect with
* `selector` - *(optional)* a value transformer function to be used for comparisons> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}(async function () {
const q = await itiririAsync(generator())
.intersect([1, 2, 4])
.awaitAll();
q.toArray(); // returns: [1, 2]
})();
````intersect` *is a deferred method and is executed only when the result sequence is iterated.*
### `join`
Returns a sequence of correlated elements transformation that match a given key.
> Syntax
```ts
join(
other: Iterable,
leftKeySelector: (element: T, index: number) => TKey,
rightKeySelector: (element: TRight, index: number) => TKey,
joinSelector: (left: T, right: TRight) => TResult,
): AsyncIterableQuery;
```> Parameters
* `other` - *(required)* sequence to join
* `leftKeySelector` - *(required)* function that provides the key of each element from source sequence
* `rightKeySelector` - *(required)* function that provides the key of each element from joined sequence
* `joinSelector` - *(required)* a transformation function to apply on each matched tupleThe `join` method works as an sql inner join.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}(async function () {
const q = await itiririAsync(generator())
.join([1, 1, 2], x => x, x => x, (x, y) => ({ x, y }))
.awaitAll();
q.toArray(); // returns: [ { x: 1, y: 1 }, { x: 1, y: 1 }, { x: 2, y: 2 } ]
})();
````join` *is a deferred method and is executed only when the result sequence is iterated.*
### `keys`
Returns a sequence of keys for each index in the source sequence.
> Syntax
```ts
keys(): AsyncIterableQuery;
```> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* ['a', 'b', 'c'];
}(async function () {
const q = await itiririAsync(generator()).keys().awaitAll();
q.toArray(); // returns: [0, 1, 2]
})();
````keys` *is a deferred method and is executed only when the result sequence is iterated.*
### `last`
Returns the last element in a sequence.
> Syntax
```ts
last(): Promise;
```For an empty sequence returns `undefined`.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3, -2];
}(async function () {
await itiririAsync(generator()).last(); // returns: -2
})();
```### `lastIndexOf`
Returns the last index at which a given element can be found.
> Syntax
```ts
lastIndexOf(element: T): Promise;
lastIndexOf(element: T, fromIndex: number): Promise;
```> Parameters
* `element` - *(required)* the element to search for
* `fromIndex` - *(optional)* starting index, defaults to `0`When an element is not found, returns -1.
`lastIndexOf` uses triple equals `===` to compare elements.> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3, 2, 1];
}(async function () {
await itiririAsync(generator()).lastIndexOf(2); // returns: 3
})();
```### `leftJoin`
Returns a sequence of correlated elements transformation that match a given key.
> Syntax
```ts
leftJoin(
other: Iterable,
leftKeySelector: (element: T, index: number) => TKey,
rightKeySelector: (element: TRight, index: number) => TKey,
joinSelector: (left: T, right?: TRight) => TResult,
): AsyncIterableQuery;
```> Parameters
* `other` - *(required)* sequence to join
* `leftKeySelector` - *(required)* function that provides the key of each element from source sequence
* `rightKeySelector` - *(required)* function that provides the key of each element from joined sequence
* `joinSelector` - *(required)* a transformation function to apply on each matched tupleThe `leftJoin` method works as an sql left join.
When an element from the left sequence doesn't match with any of the elements from the right sequence,
the `joinSelector` function is called with an `undefined` right value.> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}(async function () {
const q = await itiririAsync(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.*
### `length`
Returns the number of elements in a sequence.
> Syntax
```ts
length(): Promise;
length(predicate: (element: T, index: number) => boolean): Promise;
```> Parameters
* `predicate` - *(optional)* a function to count only the elements that match the predicate> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}(async function () {
await itiririAsync(generator()).length(); // returns 3
})();
```### `map`
Returns a sequence of transformed values.
> Syntax
```ts
map(selector: (element: T, index: number) => S): AsyncIterableQuery;
```> Parameters
* `selector` - *(required)* a value transformer function to apply to each element> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}function x10(numbers: AsyncIterable) {
return itiririAsync(numbers).map(n => n * 10);
}(async function(){
const numbers = await x10(generator()).awaitAll();
console.log(numbers); // [10, 20, 30]
})();
````map` *is a deferred method and is executed only when the result sequence is iterated.*
### `max`
Returns the maximum element in a sequence.
> Syntax
```ts
max(): Promise;
max(compareFn: (a: T, b: T) => number): Promise;
```> Parameters
* `compareFn` - *(optional)* a comparer function that compares two elements from a sequence and returns:
* `-1` when `a` is less than `b`
* `1` when `a` is greater `b`
* `0` when `a` equals to `b`If sequence is empty, returns `undefined`.
> Example
```ts
async function* generator1() {
yield* [1, 42, 3];
}async function* generator2() {
yield* [];
}(async function () {
await itiririAsync(generator1()).max(); // returns 42
await itiririAsync(generator2()).max(); // returns undefined
})();
```### `min`
Returns the minimum element in a sequence.
> Syntax
```ts
min(): Promise;
min(compareFn: (a: T, b: T) => number): Promise;
```> Parameters
* `compareFn` - *(optional)* a comparer function that compares two elements from a sequence and returns:
* `-1` when `a` is less than `b`
* `1` when `a` is greater `b`
* `0` when `a` equals to `b`If sequence is empty, returns `undefined`.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator1() {
yield* [1, -2, 3];
}async function* generator2() {
yield* [];
}(async function () {
await itiririAsync(generator1()).min(); // returns -1
await itiririAsync(generator2()).min(); // returns undefined
})();
```### `nth`
Returns the element at a specified index.
> Syntax
```ts
nth(index: number): Promise;
```> Parameters
* `index` - *(required)* zero based index at which to get the elementIf index is out of the range, returns `undefined` .
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, -2, 3];
}(async function () {
await itiririAsync(generator()).nth(2); // returns: 3
await itiririAsync(generator()).nth(3); // returns: undefined
})();
```### `prepend`
Returns a sequence with given elements at the beginning.
> Syntax
```ts
prepend(other: T): AsyncIterableQuery;
prepend(other: Promise): AsyncIterableQuery;
prepend(other: Iterable): AsyncIterableQuery;
prepend(other: AsyncIterable): AsyncIterableQuery;
```> Parameters
* `other` - *(required)* the sequence to be added at the beginning> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, -2, 3];
}(async function () {
const q = await itiririAsync(generator()).prepend(4).awaitAll();
q.toArray(); // returns: [4, 1, -2, 3]
})();(async function () {
const q = await itiririAsync(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.*
### `reduce`
Applies a function against an accumulator and each element *(from left to right)* to reduce it to a single value.
> Syntax
```ts
reduce(
callback: (accumulator: T, current: T, index: number) => T,
): Promise;reduce(
callback: (accumulator: S, current: T, index: number) => S,
initialValue: S,
): Promise;
```> Parameters
* `callback` - *(required)* function to execute on each element in the sequence, taking three arguments
* `accumulator` the accumulator accumulates the callback's return values;
* `current` the current element being processed;
* `currentIndex` the index of the current element being processed;
* `initialValue` - *(optional)* value to use as the first argument to the first call of the `callback`Calling `reduce` on an empty sequence without an initial value throws an error.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}(async function () {
// 5 + 10 + 20 + 30
await itiririAsync(generator()).reduce((accum, elem) => accum + elem * 10, 5); // returns 65
})();
```### `skip`
Skips the specified number of elements from the beginning of sequence and returns the remaining ones.
> Syntax
```ts
skip(count: number): AsyncIterableQuery;
```> Parameters
* `count` - *(required)* number of elements to skipWhen *count* is greater than actual number of elements, results in an empty sequence.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}(async function () {
const q = await itiririAsync(generator()).skip(1).awaitAll();
q.toArray(); // returns: [2, 3]
})();(async function () {
const q = await itiririAsync(generator()).skip(10).awaitAll();
q.toArray(); // returns: []
})();
````skip` *is a deferred method and is executed only when the result sequence is iterated.*
### `slice`
Returns a sequence that represents the range of elements from start to end.
> Syntax
```ts
slice(start: number, end: number): AsyncIterableQuery;
```> Parameters
* `start` - *(required)* zero-based index at which to begin extraction
* `end` - *(required)* zero-based index before which to end extraction.The `end` index is not included in the result.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3, 3, 4];
}(async function () {
const q = await itiririAsync(generator()).slice(2, 4).awaitAll();
q.toArray(); // returns: [3, 3]
})();
````slice` *is a deferred method and is executed only when the result sequence is iterated.*
### `some`
Tests whether at least one element passes the predicate.
> Syntax
```ts
some(predicate: (element: T, index: number) => boolean): Promise;
```> Parameters
* `predicate` - *(required)* function to test for each element> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3, -3, 4, 0];
}(async function () {
await itiririAsync(generator()).some(x => x < 0); // returns: true
await itiririAsync(generator()).some(x => x > 5); // returns: false
})();
```### `sum`
Returns the sum of all elements.
> Syntax
```ts
sum(): number;
sum(selector: (element: T, index: number) => number): Promise;
```> Parameters
* `selector` - *(optional)* a value transformer function to apply to each elementOptionally, a function can be provided to apply a transformation and map each element to a value.
> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator1() {
yield* [1, 2, 3];
}async function* generator2() {
yield* [{ val: 3 }, { val: 5 }];
}(async function () {
await itiririAsync(generator1()).sum(); // returns: 6
await itiririAsync(generator2()).sum(x => x.val); // returns: 8
})();
```### `take`
Returns a specified number of elements from the beginning of sequence.
> Syntax
```ts
take(count: number): AsyncIterableQuery;
```> Parameters
* `count` - *(required)* number of elements to take> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 2, 3];
}(async function () {
const q = await itiririAsync(generator()).take(2).awaitAll();
q.toArray(); // returns: [1, 2]
})();(async function () {
const q = await itiririAsync(generator()).take(0).awaitAll();
q.toArray(); // returns: []
})();
````take` *is a deferred method and is executed only when the result sequence is iterated.*
### `union`
Returns a set union with a given sequence.
> Syntax
```ts
union(other: AsyncIterable): AsyncIterableQuery;
union(other: AsyncIterable, selector: (element: T) => S): AsyncIterableQuery;
```> Parameters
* `other` - *(required)* the sequence to join with
* `selector` - *(optional)* a value transformer function to be used for comparisonsExample
```ts
import itiririAsync from 'itiriri-async';async function* generator1() {
yield* [1, 2, 3];
}async function* generator2() {
yield* [3, 4, 5];
}(async function () {
const q = await itiririAsync(generator1()).union(generator2()).awaitAll();
q.toArray(); // returns [1, 2, 3, 4, 5]
})();
````union` *is a deferred method and is executed only when the result sequence is iterated.*
### `values`
Returns a sequence of values for each index in the source sequence.
> Syntax
```ts
values(): AsyncIterableQuery;
```> Example
```ts
import itiririAsync from 'itiriri-async';async function* generator() {
yield* [1, 0, 2, 3];
}(async function () {
const q = await itiririAsync(generator()).values().awaitAll();
q.toArray(); // [1, 0, 2, 3]
})();
````values` *is a deferred method and is executed only when the result sequence is iterated.*
## License
[MIT](LICENSE)