Query Class
Package: @esfx/iter-query
A Query
represents a series of operations that act upon an Iterable
or ArrayLike. Evaluation of
these operations is deferred until the either a scalar value is requested from the Query
or the
Query
is iterated.
Declaration
export declare class Query<T> implements Iterable<T>
Constructors
constructor(source)
Creates a Query
from a Iterable
source.
Declaration
constructor(source: Iterable<T>);
Parameters
Methods
_from(source)
Declaration
protected _from<TNode, T extends TNode>(source: OrderedHierarchyIterable<TNode, T>): OrderedHierarchyQuery<TNode, T>;
Type Parameters
- TNode
- T
Parameters
- source
- OrderedHierarchyIterable<TNode, T>
Returns
_from(source)
Declaration
protected _from<TNode, T extends TNode>(source: HierarchyIterable<TNode, T>): HierarchyQuery<TNode, T>;
Type Parameters
- TNode
- T
Parameters
- source
- HierarchyIterable<TNode, T>
Returns
_from(source, provider)
Declaration
protected _from<TNode, T extends TNode>(source: OrderedIterable<T>, provider: HierarchyProvider<TNode>): OrderedHierarchyQuery<TNode, T>;
Type Parameters
- TNode
- T
Parameters
- source
- OrderedIterable<T>
- provider
- HierarchyProvider<TNode>
Returns
_from(source, provider)
Declaration
protected _from<TNode, T extends TNode>(source: Iterable<T>, provider: HierarchyProvider<TNode>): HierarchyQuery<TNode, T>;
Type Parameters
- TNode
- T
Parameters
- source
- Iterable<T>
- provider
- HierarchyProvider<TNode>
Returns
_from(source)
Declaration
protected _from<T>(source: OrderedIterable<T>): OrderedQuery<T>;
Type Parameters
- T
Parameters
- source
- OrderedIterable<T>
Returns
_from(source)
Declaration
protected _from<T extends readonly unknown[] | []>(source: Iterable<T>): Query<T>;
Type Parameters
- T
Parameters
- source
- Iterable<T>
Returns
_from(source)
Declaration
protected _from<T>(source: Iterable<T>): Query<T>;
Type Parameters
- T
Parameters
- source
- Iterable<T>
Returns
[Symbol.iterator]()
Declaration
[Symbol.iterator](): Iterator<T>;
Returns
append(value)
Creates a subquery for the elements of this Query
with the provided value appended to the end.
Declaration
append(value: T): UnorderedQueryFlow<this, T>;
Parameters
- value
- T
The value to append. Subquery
Returns
average()
Computes the average for a series of numbers.
Scalar
Declaration
average(): T extends number ? number : never;
Returns
average(elementSelector)
Computes the average for a series of numbers.
Scalar
Declaration
average(elementSelector: (element: T) => number): number;
Parameters
- elementSelector
- (element: T) => number
Returns
break(predicate)
Creates a tuple whose first element is a subquery containing the first span of elements that do not match the supplied predicate, and whose second element is a subquery containing the remaining elements.
The first subquery is eagerly evaluated, while the second subquery is lazily evaluated.
NOTE: This is an alias for spanUntil
.
Declaration
break(predicate: (element: T, offset: number) => boolean): [UnorderedQueryFlow<this, T>, UnorderedQueryFlow<this, T>];
Parameters
- predicate
- (element: T, offset: number) => boolean
The predicate used to match elements. Scalar
Returns
concat(right)
Creates a subquery that concatenates this Query
with another Iterable
.
Declaration
concat<R extends Iterable<T>>(right: R): MergeQueryFlow<this, R, T>;
Type Parameters
- R
Parameters
- right
- R
A Iterable
object.
Subquery
Returns
concat(right)
Creates a subquery that concatenates this Query
with another Iterable
.
Declaration
concat(right: Iterable<T>): Query<T>;
Parameters
Returns
consume(iterator, options)
Creates a Query
that, when iterated, consumes the provided Iterator
.
Declaration
static consume<T>(iterator: Iterator<T>, options?: ConsumeOptions): Query<T>;
Type Parameters
- T
Parameters
- options
- ConsumeOptions
Returns
continuous(value)
Creates a Query
that repeats the provided value forever.
Declaration
static continuous<T>(value: T): Query<T>;
Type Parameters
- T
Parameters
- value
- T
The value for each element of the Query
.
Query
Returns
copyTo(dest, start, count)
Writes each element to a destination. The destination must already have enough space to write the requested number of elements (i.e. arrays are *not* resized).
Declaration
copyTo(dest: T[], start?: number, count?: number): T[];
Parameters
- dest
- T[]
The destination array.
Returns
copyTo(dest, start, count)
Writes each element to a destination. The destination must already have enough space to write the requested number of elements (i.e. arrays are *not* resized).
Declaration
copyTo<U extends IndexedCollection<T>>(dest: U, start?: number, count?: number): U;
Type Parameters
- U
Parameters
- dest
- U
The destination array.
Returns
corresponds(right, equaler)
Computes a scalar value indicating whether every element in this Query
corresponds to a matching element
in another Iterable
at the same position.
Declaration
corresponds(right: Iterable<T>, equaler?: EqualityComparison<T> | Equaler<T>): boolean;
Parameters
- equaler
- EqualityComparison<T> | Equaler<T>
An optional callback used to compare the equality of two elements. Scalar
Returns
corresponds(right, equaler)
Computes a scalar value indicating whether every element in this Query
corresponds to a matching element
in another Iterable
at the same position.
Declaration
corresponds<U>(right: Iterable<U>, equaler: (left: T, right: U) => boolean): boolean;
Type Parameters
- U
Parameters
- equaler
- (left: T, right: U) => boolean
An optional callback used to compare the equality of two elements. Scalar
Returns
correspondsBy(right, keySelector, keyEqualer)
Computes a scalar value indicating whether every element in this Query
corresponds to a matching element
in another Iterable
at the same position.
Declaration
correspondsBy<K>(right: Iterable<T>, keySelector: (element: T) => K, keyEqualer?: Equaler<K>): boolean;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
correspondsBy(right, leftKeySelector, rightKeySelector, keyEqualer)
Computes a scalar value indicating whether the key for every element in this Query
corresponds to a matching key
in right
at the same position.
Declaration
correspondsBy<U, K>(right: Iterable<U>, leftKeySelector: (element: T) => K, rightKeySelector: (element: U) => K, keyEqualer?: EqualityComparison<K> | Equaler<K>): boolean;
Type Parameters
- U
- K
Parameters
- leftKeySelector
- (element: T) => K
A callback used to select the key for each element in this Query
.
- rightKeySelector
- (element: U) => K
A callback used to select the key for each element in right
.
- keyEqualer
- EqualityComparison<K> | Equaler<K>
An optional callback used to compare the equality of two keys. Scalar
Returns
count(predicate)
Counts the number of elements in the Query
, optionally filtering elements using the supplied
callback.
Declaration
count(predicate?: (element: T) => boolean): number;
Parameters
- predicate
- (element: T) => boolean
An optional callback used to match each element. Scalar
Returns
defaultIfEmpty(defaultValue)
Creates a subquery that contains the provided default value if this Query
contains no elements.
Declaration
defaultIfEmpty(defaultValue: T): UnorderedQueryFlow<this, T>;
Parameters
- defaultValue
- T
The default value. Subquery
Returns
distinct(equaler)
Creates a subquery for the distinct elements of this Query
.
Declaration
distinct(equaler?: Equaler<T>): UnorderedQueryFlow<this, T>;
Parameters
Returns
distinctBy(keySelector, keyEqualer)
Creates a subquery for the distinct elements of this Query
.
Declaration
distinctBy<K>(keySelector: (value: T) => K, keyEqualer?: Equaler<K>): UnorderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (value: T) => K
A callback used to select the key to determine uniqueness.
Returns
drop(count)
Creates a subquery containing all elements except the first elements up to the supplied count.
Declaration
drop(count: number): UnorderedQueryFlow<this, T>;
Parameters
Returns
dropRight(count)
Creates a subquery containing all elements except the last elements up to the supplied count.
Declaration
dropRight(count: number): UnorderedQueryFlow<this, T>;
Parameters
Returns
dropUntil(predicate)
Creates a subquery containing all elements except the first elements that don't match the supplied predicate.
Declaration
dropUntil(predicate: (element: T) => boolean): UnorderedQueryFlow<this, T>;
Parameters
- predicate
- (element: T) => boolean
A callback used to match each element.
Returns
dropWhile(predicate)
Creates a subquery containing all elements except the first elements that match the supplied predicate.
Declaration
dropWhile(predicate: (element: T) => boolean): UnorderedQueryFlow<this, T>;
Parameters
- predicate
- (element: T) => boolean
A callback used to match each element.
Returns
elementAt(offset)
Finds the value in the Query
at the provided offset. A negative offset starts from the
last element.
Declaration
elementAt(offset: number | Index): T | undefined;
Parameters
Returns
empty()
Creates a Query
with no elements.
Query
Declaration
static empty<T>(): Query<T>;
Type Parameters
- T
Returns
endsWith(right, equaler)
Computes a scalar value indicating whether the elements of this Query
end
with the same sequence of elements in another Iterable
.
Declaration
endsWith(right: Iterable<T>, equaler?: EqualityComparison<T> | Equaler<T>): boolean;
Parameters
- equaler
- EqualityComparison<T> | Equaler<T>
A callback used to compare the equality of two elements. Scalar
Returns
endsWith(right, equaler)
Computes a scalar value indicating whether the elements of this Query
end
with the same sequence of elements in another Iterable
.
Declaration
endsWith<U>(right: Iterable<U>, equaler: (left: T, right: U) => boolean): boolean;
Type Parameters
- U
Parameters
- equaler
- (left: T, right: U) => boolean
A callback used to compare the equality of two elements. Scalar
Returns
every(predicate)
Computes a scalar value indicating whether all elements of the Query
match the supplied callback.
Declaration
every<U extends T>(predicate: (element: T) => element is U): this is Query<U>;
Type Parameters
- U
Parameters
- predicate
- (element: T) => element is U
A callback used to match each element. Scalar
Returns
every(predicate)
Computes a scalar value indicating whether all elements of the Query
match the supplied callback.
Declaration
every(predicate: (element: T) => boolean): boolean;
Parameters
- predicate
- (element: T) => boolean
A callback used to match each element. Scalar
Returns
except(right, equaler)
Creates a subquery for the set difference between this and another Iterable
.
Declaration
except(right: Iterable<T>, equaler?: Equaler<T>): UnorderedQueryFlow<this, T>;
Parameters
Returns
exceptBy(right, keySelector, keyEqualer)
Creates a subquery for the set difference between this and another Iterable
, where set identity is determined by the selected key.
Declaration
exceptBy<K>(right: Iterable<T>, keySelector: (element: T) => K, keyEqualer?: Equaler<K>): UnorderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
exclude(values)
Creates a subquery with every instance of the specified value removed.
Declaration
exclude(...values: [T, ...T[]]): UnorderedQueryFlow<this, T>;
Parameters
- values
- [T, ...T[]]
The values to exclude. Subquery
Returns
filter(predicate)
Creates a subquery whose elements match the supplied predicate.
Declaration
filter<U extends T>(predicate: (element: T, offset: number) => element is U): UnorderedQueryFlow<this, U>;
Type Parameters
- U
Parameters
- predicate
- (element: T, offset: number) => element is U
A callback used to match each element.
Returns
filter(predicate)
Creates a subquery whose elements match the supplied predicate.
Declaration
filter(predicate: (element: T, offset: number) => boolean): UnorderedQueryFlow<this, T>;
Parameters
- predicate
- (element: T, offset: number) => boolean
A callback used to match each element.
Returns
filterBy(keySelector, predicate)
Creates a subquery where the selected key for each element matches the supplied predicate.
Declaration
filterBy<K>(keySelector: (element: T) => K, predicate: (key: K, offset: number) => boolean): UnorderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
- predicate
- (key: K, offset: number) => boolean
A callback used to match each key.
Returns
filterDefined()
Creates a subquery whose elements are neither null
nor undefined
.
Subquery
Declaration
filterDefined(): UnorderedQueryFlow<this, NonNullable<T>>;
Returns
filterDefinedBy(keySelector)
Creates a subquery where the selected key for each element is neither null
nor undefined
.
Declaration
filterDefinedBy<K>(keySelector: (element: T) => K): UnorderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
filterNot(predicate)
Creates a subquery whose elements do not match the supplied predicate.
Declaration
filterNot<U extends T>(predicate: (element: T, offset: number) => element is U): UnorderedQueryFlow<this, U>;
Type Parameters
- U
Parameters
- predicate
- (element: T, offset: number) => element is U
A callback used to match each element.
Returns
filterNot(predicate)
Creates a subquery whose elements do not match the supplied predicate.
Declaration
filterNot(predicate: (element: T, offset: number) => boolean): UnorderedQueryFlow<this, T>;
Parameters
- predicate
- (element: T, offset: number) => boolean
A callback used to match each element.
Returns
filterNotBy(keySelector, predicate)
Creates a subquery where the selected key for each element does not match the supplied predicate.
Declaration
filterNotBy<K>(keySelector: (element: T) => K, predicate: (key: K, offset: number) => boolean): UnorderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
- predicate
- (key: K, offset: number) => boolean
A callback used to match each key.
Returns
filterNotDefinedBy(keySelector)
Creates a subquery where the selected key for each element is either null
or undefined
.
Declaration
filterNotDefinedBy<K>(keySelector: (element: T) => K): UnorderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
first(predicate)
Gets the first element in the Query
, optionally filtering elements using the supplied
callback.
Declaration
first<U extends T>(predicate: (element: T) => element is U): U | undefined;
Type Parameters
- U
Parameters
- predicate
- (element: T) => element is U
An optional callback used to match each element. Scalar
Returns
first(predicate)
Gets the first element in the Query
, optionally filtering elements using the supplied
callback.
Declaration
first(predicate?: (element: T) => boolean): T | undefined;
Parameters
- predicate
- (element: T) => boolean
An optional callback used to match each element. Scalar
Returns
flatMap(projection)
Creates a subquery that iterates the results of applying a callback to each element.
Declaration
flatMap<U>(projection: (element: T) => Iterable<U>): Query<U>;
Type Parameters
- U
Parameters
Returns
flatMap(projection, resultSelector)
Creates a subquery that iterates the results of applying a callback to each element.
Declaration
flatMap<U, R>(projection: (element: T) => Iterable<U>, resultSelector: (element: T, innerElement: U) => R): Query<R>;
Type Parameters
- U
- R
Parameters
- resultSelector
- (element: T, innerElement: U) => R
An optional callback used to map the outer and projected inner elements.
Returns
forEach(callback)
Invokes a callback for each element of the Query
.
Declaration
forEach(callback: (element: T, offset: number) => void): void;
Parameters
- callback
- (element: T, offset: number) => void
The callback to invoke. Scalar
Returns
from(source)
Creates a Query
from a Iterable
source.
Query
Declaration
static from<TNode, T extends TNode>(source: OrderedHierarchyIterable<TNode, T>): OrderedHierarchyQuery<TNode, T>;
Type Parameters
- TNode
- T
Parameters
- source
- OrderedHierarchyIterable<TNode, T>
Returns
from(source)
Declaration
static from<TNode, T extends TNode>(source: HierarchyIterable<TNode, T>): HierarchyQuery<TNode, T>;
Type Parameters
- TNode
- T
Parameters
- source
- HierarchyIterable<TNode, T>
Returns
from(source, provider)
Declaration
static from<TNode, T extends TNode>(source: OrderedIterable<T>, provider: HierarchyProvider<TNode>): OrderedHierarchyQuery<TNode, T>;
Type Parameters
- TNode
- T
Parameters
- source
- OrderedIterable<T>
- provider
- HierarchyProvider<TNode>
Returns
from(source, provider)
Declaration
static from<TNode, T extends TNode>(source: Iterable<T>, provider: HierarchyProvider<TNode>): HierarchyQuery<TNode, T>;
Type Parameters
- TNode
- T
Parameters
- source
- Iterable<T>
- provider
- HierarchyProvider<TNode>
Returns
from(source)
Declaration
static from<T>(source: OrderedIterable<T>): OrderedQuery<T>;
Type Parameters
- T
Parameters
- source
- OrderedIterable<T>
Returns
from(source)
Declaration
static from<T extends readonly unknown[] | []>(source: Iterable<T>): Query<T>;
Type Parameters
- T
Parameters
- source
- Iterable<T>
Returns
from(source)
Declaration
static from<T>(source: Iterable<T>): Query<T>;
Type Parameters
- T
Parameters
- source
- Iterable<T>
Returns
fullJoin(inner, outerKeySelector, innerKeySelector, resultSelector, keyEqualer)
Creates a subquery for the correlated elements of this Query
and another Iterable
.
Declaration
fullJoin<I, K, R>(inner: Iterable<I>, outerKeySelector: (element: T) => K, innerKeySelector: (element: I) => K, resultSelector: (outer: T | undefined, inner: I | undefined) => R, keyEqualer?: Equaler<K>): Query<R>;
Type Parameters
- I
- K
- R
Parameters
- outerKeySelector
- (element: T) => K
A callback used to select the key for an element in this Query
.
- innerKeySelector
- (element: I) => K
A callback used to select the key for an element in the other Iterable.
- resultSelector
- (outer: T | undefined, inner: I | undefined) => R
A callback used to select the result for the correlated elements.
Returns
generate(count, generator)
Creates a Query
whose values are provided by a callback executed a provided number of
times.
Declaration
static generate<T>(count: number, generator: (offset: number) => T): Query<T>;
Type Parameters
- T
Parameters
- generator
- (offset: number) => T
The callback to execute. Query
Returns
groupBy(keySelector, keyEqualer)
Groups each element of this Query
by its key.
Declaration
groupBy<K>(keySelector: (element: T) => K, keyEqualer?: Equaler<K>): GroupedQueryFlow<this, K, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for an element.
Returns
groupBy(keySelector, elementSelector, keyEqualer)
Groups each element by its key.
Declaration
groupBy<K, V>(keySelector: (element: T) => K, elementSelector: (element: T) => V, keyEqualer?: Equaler<K>): GroupedQueryFlow<this, K, V>;
Type Parameters
- K
- V
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for an element.
- elementSelector
- (element: T) => V
A callback used to select a value for an element.
Returns
groupBy(keySelector, elementSelector, resultSelector, keyEqualer)
Groups each element by its key.
Declaration
groupBy<K, V, R>(keySelector: (element: T) => K, elementSelector: (element: T) => V, resultSelector: (key: K, elements: Query<V>) => R, keyEqualer?: Equaler<K>): Query<R>;
Type Parameters
- K
- V
- R
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for an element.
- elementSelector
- (element: T) => V
A callback used to select a value for an element.
Returns
groupBy(keySelector, elementSelector, resultSelector, keyEqualer)
Groups each element by its key.
Declaration
groupBy<K, R>(keySelector: (element: T) => K, elementSelector: undefined, resultSelector: (key: K, elements: Query<T>) => R, keyEqualer?: Equaler<K>): Query<R>;
Type Parameters
- K
- R
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for an element.
Returns
groupJoin(inner, outerKeySelector, innerKeySelector, resultSelector, keyEqualer)
Creates a grouped subquery for the correlated elements of this Query
and another Iterable
object.
Declaration
groupJoin<I, K, R>(inner: Iterable<I>, outerKeySelector: (element: T) => K, innerKeySelector: (element: I) => K, resultSelector: (outer: T, inner: Query<I>) => R, keyEqualer?: Equaler<K>): Query<R>;
Type Parameters
- I
- K
- R
Parameters
- outerKeySelector
- (element: T) => K
A callback used to select the key for an element in this Query
.
- innerKeySelector
- (element: I) => K
A callback used to select the key for an element in the other Iterable
object.
- resultSelector
- (outer: T, inner: Query<I>) => R
A callback used to select the result for the correlated elements.
Returns
includes(value, equaler)
Computes a scalar value indicating whether the provided value is included in the Query
.
Declaration
includes(value: T, equaler?: EqualityComparison<T> | Equaler<T>): boolean;
Parameters
- value
- T
A value.
- equaler
- EqualityComparison<T> | Equaler<T>
An optional callback used to compare the equality of two elements. Scalar
Returns
includes(value, equaler)
Computes a scalar value indicating whether the provided value is included in the Query
.
Declaration
includes<U>(value: U, equaler: (left: T, right: U) => boolean): boolean;
Type Parameters
- U
Parameters
- value
- U
A value.
- equaler
- (left: T, right: U) => boolean
An optional callback used to compare the equality of two elements. Scalar
Returns
includesSequence(right, equaler)
Computes a scalar value indicating whether the elements of this Query
include
an exact sequence of elements from another Iterable
.
Declaration
includesSequence(right: Iterable<T>, equaler?: EqualityComparison<T> | Equaler<T>): boolean;
Parameters
- equaler
- EqualityComparison<T> | Equaler<T>
A callback used to compare the equality of two elements. Scalar
Returns
includesSequence(right, equaler)
Computes a scalar value indicating whether the elements of this Query
include
an exact sequence of elements from another Iterable
.
Declaration
includesSequence<U>(right: Iterable<U>, equaler: (left: T, right: U) => boolean): boolean;
Type Parameters
- U
Parameters
- equaler
- (left: T, right: U) => boolean
A callback used to compare the equality of two elements. Scalar
Returns
intersect(right, equaler)
Creates a subquery for the set intersection of this Query
and another Iterable
.
Declaration
intersect<R extends Iterable<T>>(right: R, equaler?: Equaler<T>): MergeQueryFlow<this, R, T>;
Type Parameters
- R
Parameters
- right
- R
A Iterable
object.
Returns
intersect(right, equaler)
Declaration
intersect(right: Iterable<T>, equaler?: Equaler<T>): Query<T>;
Parameters
- right
- Iterable<T>
- equaler
- Equaler<T>
Returns
intersectBy(right, keySelector, keyEqualer)
Creates a subquery for the set intersection of this Query
and another Iterable
, where set identity is determined by the selected key.
Declaration
intersectBy<K, R extends Iterable<T>>(right: R, keySelector: (element: T) => K, keyEqualer?: Equaler<K>): MergeQueryFlow<this, R, T>;
Type Parameters
- K
- R
Parameters
- right
- R
A Iterable
object.
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
intersectBy(right, keySelector, keyEqualer)
Creates a subquery for the set intersection of this Query
and another Iterable
, where set identity is determined by the selected key.
Declaration
intersectBy<K>(right: Iterable<T>, keySelector: (element: T) => K, keyEqualer?: Equaler<K>): Query<T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
into(callback)
Pass the entire Query
to the provided callback, returning the result.
Declaration
into<R>(callback: (source: this) => R): R;
Type Parameters
- R
Parameters
- callback
- (source: this) => R
A callback function.
Returns
join(inner, outerKeySelector, innerKeySelector, resultSelector, keyEqualer)
Creates a subquery for the correlated elements of this Query
and another Iterable
.
Declaration
join<I, K, R>(inner: Iterable<I>, outerKeySelector: (element: T) => K, innerKeySelector: (element: I) => K, resultSelector: (outer: T, inner: I) => R, keyEqualer?: Equaler<K>): Query<R>;
Type Parameters
- I
- K
- R
Parameters
- outerKeySelector
- (element: T) => K
A callback used to select the key for an element in this Query
.
- innerKeySelector
- (element: I) => K
A callback used to select the key for an element in the other Iterable.
- resultSelector
- (outer: T, inner: I) => R
A callback used to select the result for the correlated elements.
Returns
last(predicate)
Gets the last element in the Query
, optionally filtering elements using the supplied
callback.
Declaration
last<U extends T>(predicate: (element: T) => element is U): U | undefined;
Type Parameters
- U
Parameters
- predicate
- (element: T) => element is U
An optional callback used to match each element. Scalar
Returns
last(predicate)
Gets the last element in the Query
, optionally filtering elements using the supplied
callback.
Declaration
last(predicate?: (element: T) => boolean): T | undefined;
Parameters
- predicate
- (element: T) => boolean
An optional callback used to match each element. Scalar
Returns
map(selector)
Creates a subquery by applying a callback to each element.
Declaration
map<U>(selector: (element: T, offset: number) => U): Query<U>;
Type Parameters
- U
Parameters
- selector
- (element: T, offset: number) => U
A callback used to map each element.
Returns
materialize()
Eagerly evaluate the Query
, returning a new Query
.
Subquery
Declaration
materialize(): UnorderedQueryFlow<this, T>;
Returns
max(comparer)
Gets the maximum element in the Query
, optionally comparing elements using the supplied
callback.
Declaration
max(comparer?: Comparison<T> | Comparer<T>): T | undefined;
Parameters
Returns
maxBy(keySelector, keyComparer)
Gets the maximum element by its key in the Query
, optionally comparing the keys of each element using the supplied callback.
Declaration
maxBy<K>(keySelector: (element: T) => K, keyComparer?: Comparison<K> | Comparer<K>): T | undefined;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to choose the key to compare.
Returns
min(comparer)
Gets the minimum element in the Query
, optionally comparing elements using the supplied
callback.
Declaration
min(comparer?: Comparison<T> | Comparer<T>): T | undefined;
Parameters
Returns
minBy(keySelector, keyComparer)
Gets the minimum element by its key in the Query
, optionally comparing the keys of each element using the supplied callback.
Declaration
minBy<K>(keySelector: (element: T) => K, keyComparer?: Comparison<K> | Comparer<K>): T | undefined;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to choose the key to compare.
Returns
nth(offset)
Finds the value in the Query
at the provided offset. A negative offset starts from the
last element.
NOTE: This is an alias for elementAt
.
Declaration
nth(offset: number | Index): T | undefined;
Parameters
Returns
of(elements)
Creates a Query
for the provided elements.
Declaration
static of<T>(...elements: T[]): Query<T>;
Type Parameters
- T
Parameters
- elements
- T[]
The elements of the Query
.
Query
Returns
once(value)
Creates a Query
over a single element.
Declaration
static once<T>(value: T): Query<T>;
Type Parameters
- T
Parameters
- value
- T
The only element for the Query
.
Query
Returns
orderBy(keySelector, comparer)
Creates an ordered subquery whose elements are sorted in ascending order by the provided key.
Declaration
orderBy<K>(keySelector: (element: T) => K, comparer?: Comparison<K> | Comparer<K>): OrderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for an element.
Returns
orderByDescending(keySelector, comparer)
Creates an ordered subquery whose elements are sorted in descending order by the provided key.
Declaration
orderByDescending<K>(keySelector: (element: T) => K, comparer?: Comparison<K> | Comparer<K>): OrderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for an element.
Returns
pageBy(pageSize)
Creates a subquery that splits this Query
into one or more pages.
While advancing from page to page is evaluated lazily, the elements of the page are
evaluated eagerly.
Declaration
pageBy(pageSize: number): PagedQueryFlow<this, T>;
Parameters
Returns
pageBy(pageSize, pageSelector)
Creates a subquery that splits this Query
into one or more pages.
While advancing from page to page is evaluated lazily, the elements of the page are
evaluated eagerly.
Declaration
pageBy<R>(pageSize: number, pageSelector: (page: number, offset: number, values: UnorderedQueryFlow<this, T>) => R): Query<R>;
Type Parameters
- R
Parameters
- pageSelector
- (page: number, offset: number, values: UnorderedQueryFlow<this, T>) => R
Returns
patch(start, skipCount, range)
Creates a subquery for the elements of this Query
with the provided range
patched into the results.
Declaration
patch(start: number, skipCount?: number, range?: Iterable<T>): UnorderedQueryFlow<this, T>;
Parameters
Returns
prepend(value)
Creates a subquery for the elements of this Query
with the provided value prepended to the beginning.
Declaration
prepend(value: T): UnorderedQueryFlow<this, T>;
Parameters
- value
- T
The value to prepend. Subquery
Returns
range(start, end, increment)
Creates a Query
over a range of numbers.
Declaration
static range(start: number, end: number, increment?: number): Query<number>;
Parameters
Returns
reduce(accumulator)
Computes a scalar value by applying an accumulator callback over each element.
Declaration
reduce(accumulator: (current: T, element: T, offset: number) => T): T;
Parameters
- accumulator
- (current: T, element: T, offset: number) => T
the callback used to compute the result.
Returns
reduce(accumulator, seed, resultSelector)
Computes a scalar value by applying an accumulator callback over each element.
Declaration
reduce<U>(accumulator: (current: U, element: T, offset: number) => U, seed: U, resultSelector?: (result: U, count: number) => U): U;
Type Parameters
- U
Parameters
- accumulator
- (current: U, element: T, offset: number) => U
the callback used to compute the result.
- seed
- U
An optional seed value. Scalar
- resultSelector
- (result: U, count: number) => U
Returns
reduce(accumulator, seed, resultSelector)
Computes a scalar value by applying an accumulator callback over each element.
Declaration
reduce<U, R>(accumulator: (current: U, element: T, offset: number) => U, seed: U, resultSelector: (result: U, count: number) => R): R;
Type Parameters
- U
- R
Parameters
- accumulator
- (current: U, element: T, offset: number) => U
the callback used to compute the result.
- seed
- U
An optional seed value.
- resultSelector
- (result: U, count: number) => R
An optional callback used to compute the final result. Scalar
Returns
reduceRight(accumulator)
Computes a scalar value by applying an accumulator callback over each element in reverse.
Declaration
reduceRight(accumulator: (current: T, element: T, offset: number) => T): T;
Parameters
- accumulator
- (current: T, element: T, offset: number) => T
the callback used to compute the result. Scalar
Returns
reduceRight(accumulator, seed, resultSelector)
Computes a scalar value by applying an accumulator callback over each element in reverse.
Declaration
reduceRight<U>(accumulator: (current: U, element: T, offset: number) => U, seed: U, resultSelector?: (result: U, count: number) => U): U;
Type Parameters
- U
Parameters
- accumulator
- (current: U, element: T, offset: number) => U
the callback used to compute the result.
- seed
- U
An optional seed value. Scalar
- resultSelector
- (result: U, count: number) => U
Returns
reduceRight(accumulator, seed, resultSelector)
Computes a scalar value by applying an accumulator callback over each element in reverse.
Declaration
reduceRight<U, R>(accumulator: (current: U, element: T, offset: number) => U, seed: U, resultSelector: (result: U, count: number) => R): R;
Type Parameters
- U
- R
Parameters
- accumulator
- (current: U, element: T, offset: number) => U
the callback used to compute the result.
- seed
- U
An optional seed value.
- resultSelector
- (result: U, count: number) => R
An optional callback used to compute the final result. Scalar
Returns
relativeComplement(right, equaler)
Creates a subquery for the set difference between this and another Iterable
.
NOTE: This is an alias for except
.
Declaration
relativeComplement(right: Iterable<T>, equaler?: Equaler<T>): UnorderedQueryFlow<this, T>;
Parameters
Returns
relativeComplementBy(right, keySelector, keyEqualer)
Creates a subquery for the set difference between this and another Iterable
, where set identity is determined by the selected key.
NOTE: This is an alias for exceptBy
.
Declaration
relativeComplementBy<K>(right: Iterable<T>, keySelector: (element: T) => K, keyEqualer?: Equaler<K>): UnorderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
repeat(value, count)
Creates a Query
for a value repeated a provided number of times.
Declaration
static repeat<T>(value: T, count: number): Query<T>;
Type Parameters
- T
Parameters
- value
- T
The value for each element of the Query
.
Returns
reverse()
Creates a subquery whose elements are in the reverse order.
Subquery
Declaration
reverse(): UnorderedQueryFlow<this, T>;
Returns
scan(accumulator)
Creates a subquery containing the cumulative results of applying the provided callback to each element.
Declaration
scan(accumulator: (current: T, element: T, offset: number) => T): Query<T>;
Parameters
- accumulator
- (current: T, element: T, offset: number) => T
The callback used to compute each result.
Returns
scan(accumulator, seed)
Creates a subquery containing the cumulative results of applying the provided callback to each element.
Declaration
scan<U>(accumulator: (current: U, element: T, offset: number) => U, seed: U): Query<U>;
Type Parameters
- U
Parameters
- accumulator
- (current: U, element: T, offset: number) => U
The callback used to compute each result.
- seed
- U
An optional seed value. Subquery
Returns
scanRight(accumulator)
Creates a subquery containing the cumulative results of applying the provided callback to each element in reverse.
Declaration
scanRight(accumulator: (current: T, element: T, offset: number) => T): Query<T>;
Parameters
- accumulator
- (current: T, element: T, offset: number) => T
The callback used to compute each result.
Returns
scanRight(accumulator, seed)
Creates a subquery containing the cumulative results of applying the provided callback to each element in reverse.
Declaration
scanRight<U>(accumulator: (current: U, element: T, offset: number) => U, seed?: U): Query<U>;
Type Parameters
- U
Parameters
- accumulator
- (current: U, element: T, offset: number) => U
The callback used to compute each result.
- seed
- U
An optional seed value. Subquery
Returns
select(selector)
Creates a subquery by applying a callback to each element.
NOTE: This is an alias for map
.
Declaration
select<U>(selector: (element: T, offset: number) => U): Query<U>;
Type Parameters
- U
Parameters
- selector
- (element: T, offset: number) => U
A callback used to map each element.
Returns
selectMany(projection)
Creates a subquery that iterates the results of applying a callback to each element.
NOTE: This is an alias for flatMap
.
Declaration
selectMany<U>(projection: (element: T) => Iterable<U>): Query<U>;
Type Parameters
- U
Parameters
Returns
selectMany(projection, resultSelector)
Creates a subquery that iterates the results of applying a callback to each element.
NOTE: This is an alias for flatMap
.
Declaration
selectMany<U, R>(projection: (element: T) => Iterable<U>, resultSelector: (element: T, innerElement: U) => R): Query<R>;
Type Parameters
- U
- R
Parameters
- resultSelector
- (element: T, innerElement: U) => R
An optional callback used to map the outer and projected inner elements.
Returns
single(predicate)
Gets the only element in the Query
, or returns undefined
.
Declaration
single<U extends T>(predicate: (element: T) => element is U): U | undefined;
Type Parameters
- U
Parameters
- predicate
- (element: T) => element is U
An optional callback used to match each element. Scalar
Returns
single(predicate)
Gets the only element in the Query
, or returns undefined.
Declaration
single(predicate?: (element: T) => boolean): T | undefined;
Parameters
- predicate
- (element: T) => boolean
An optional callback used to match each element. Scalar
Returns
skip(count)
Creates a subquery containing all elements except the first elements up to the supplied count.
NOTE: This is an alias for drop
.
Declaration
skip(count: number): UnorderedQueryFlow<this, T>;
Parameters
Returns
skipRight(count)
Creates a subquery containing all elements except the last elements up to the supplied count.
NOTE: This is an alias for dropRight
.
Declaration
skipRight(count: number): UnorderedQueryFlow<this, T>;
Parameters
Returns
skipUntil(predicate)
Creates a subquery containing all elements except the first elements that don't match the supplied predicate.
NOTE: This is an alias for dropUntil
.
Declaration
skipUntil(predicate: (element: T) => boolean): UnorderedQueryFlow<this, T>;
Parameters
- predicate
- (element: T) => boolean
A callback used to match each element.
Returns
skipWhile(predicate)
Creates a subquery containing all elements except the first elements that match the supplied predicate.
NOTE: This is an alias for dropWhile
.
Declaration
skipWhile(predicate: (element: T) => boolean): UnorderedQueryFlow<this, T>;
Parameters
- predicate
- (element: T) => boolean
A callback used to match each element.
Returns
some(predicate)
Computes a scalar value indicating whether the Query
contains any elements,
optionally filtering the elements using the supplied callback.
Declaration
some(predicate?: (element: T) => boolean): boolean;
Parameters
- predicate
- (element: T) => boolean
An optional callback used to match each element. Scalar
Returns
span(predicate)
Creates a tuple whose first element is a subquery containing the first span of elements that match the supplied predicate, and whose second element is a subquery containing the remaining elements.
The first subquery is eagerly evaluated, while the second subquery is lazily evaluated.
Declaration
span<U extends T>(predicate: (element: T, offset: number) => element is U): [UnorderedQueryFlow<this, U>, UnorderedQueryFlow<this, T>];
Type Parameters
- U
Parameters
- predicate
- (element: T, offset: number) => element is U
The predicate used to match elements. Scalar
Returns
span(predicate)
Creates a tuple whose first element is a subquery containing the first span of elements that match the supplied predicate, and whose second element is a subquery containing the remaining elements.
The first subquery is eagerly evaluated, while the second subquery is lazily evaluated.
Declaration
span(predicate: (element: T, offset: number) => boolean): [UnorderedQueryFlow<this, T>, UnorderedQueryFlow<this, T>];
Parameters
- predicate
- (element: T, offset: number) => boolean
The predicate used to match elements. Scalar
Returns
spanMap(keySelector, keyEqualer)
Creates a subquery whose elements are the contiguous ranges of elements that share the same key.
Declaration
spanMap<K>(keySelector: (element: T) => K, keyEqualer?: Equaler<K>): GroupedQueryFlow<this, K, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for an element.
- keyEqualer
- Equaler<K>
Returns
spanMap(keySelector, elementSelector, keyEqualer)
Creates a subquery whose values are computed from each element of the contiguous ranges of elements that share the same key.
Declaration
spanMap<K, V>(keySelector: (element: T) => K, elementSelector: (element: T) => V, keyEqualer?: Equaler<K>): GroupedQueryFlow<this, K, V>;
Type Parameters
- K
- V
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for an element.
- elementSelector
- (element: T) => V
A callback used to select a value for an element.
- keyEqualer
- Equaler<K>
Returns
spanMap(keySelector, elementSelector, spanSelector, keyEqualer)
Creates a subquery whose values are computed from the contiguous ranges of elements that share the same key.
Declaration
spanMap<K, V, R>(keySelector: (element: T) => K, elementSelector: (element: T) => V, spanSelector: (key: K, elements: Query<V>) => R, keyEqualer?: Equaler<K>): Query<R>;
Type Parameters
- K
- V
- R
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for an element.
- elementSelector
- (element: T) => V
A callback used to select a value for an element.
- spanSelector
- (key: K, elements: Query<V>) => R
A callback used to select a result from a contiguous range.
- keyEqualer
- Equaler<K>
Returns
spanMap(keySelector, elementSelector, spanSelector, keyEqualer)
Creates a subquery whose values are computed from the contiguous ranges of elements that share the same key.
Declaration
spanMap<K, R>(keySelector: (element: T) => K, elementSelector: undefined, spanSelector: (key: K, elements: Query<T>) => R, keyEqualer?: Equaler<K>): Query<R>;
Type Parameters
- K
- R
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for an element.
- spanSelector
- (key: K, elements: Query<T>) => R
A callback used to select a result from a contiguous range.
- keyEqualer
- Equaler<K>
Returns
spanUntil(predicate)
Creates a tuple whose first element is a subquery containing the first span of elements that do not match the supplied predicate, and whose second element is a subquery containing the remaining elements.
The first subquery is eagerly evaluated, while the second subquery is lazily evaluated.
Declaration
spanUntil(predicate: (element: T, offset: number) => boolean): [UnorderedQueryFlow<this, T>, UnorderedQueryFlow<this, T>];
Parameters
- predicate
- (element: T, offset: number) => boolean
The predicate used to match elements. Scalar
Returns
startsWith(right, equaler)
Computes a scalar value indicating whether the elements of this Query
start
with the same sequence of elements in another Iterable
.
Declaration
startsWith(right: Iterable<T>, equaler?: EqualityComparison<T> | Equaler<T>): boolean;
Parameters
- equaler
- EqualityComparison<T> | Equaler<T>
A callback used to compare the equality of two elements. Scalar
Returns
startsWith(right, equaler)
Computes a scalar value indicating whether the elements of this Query
start
with the same sequence of elements in another Iterable
.
Declaration
startsWith<U>(right: Iterable<U>, equaler: (left: T, right: U) => boolean): boolean;
Type Parameters
- U
Parameters
- equaler
- (left: T, right: U) => boolean
A callback used to compare the equality of two elements. Scalar
Returns
sum()
Computes the sum for a series of numbers.
Scalar
Declaration
sum(): T extends number ? number : never;
Returns
sum(elementSelector)
Computes the sum for a series of numbers.
Scalar
Declaration
sum(elementSelector: (element: T) => number): number;
Parameters
- elementSelector
- (element: T) => number
Returns
symmetricDifference(right, equaler)
Creates a subquery for the symmetric difference between this and another Iterable
.
Declaration
symmetricDifference<R extends Iterable<T>>(right: R, equaler?: Equaler<T>): MergeQueryFlow<this, R, T>;
Type Parameters
- R
Parameters
- right
- R
A Iterable
object.
Returns
symmetricDifference(right, equaler)
Creates a subquery for the symmetric difference between this and another Iterable
.
Declaration
symmetricDifference(right: Iterable<T>, equaler?: Equaler<T>): Query<T>;
Parameters
Returns
symmetricDifferenceBy(right, keySelector, keyEqualer)
Creates a subquery for the symmetric difference between this and another Iterable
, where set identity is determined by the selected key.
Declaration
symmetricDifferenceBy<K, R extends Iterable<T>>(right: R, keySelector: (element: T) => K, keyEqualer?: Equaler<K>): MergeQueryFlow<this, R, T>;
Type Parameters
- K
- R
Parameters
- right
- R
A Iterable
object.
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
symmetricDifferenceBy(right, keySelector, keyEqualer)
Creates a subquery for the symmetric difference between this and another Iterable
, where set identity is determined by the selected key.
Declaration
symmetricDifferenceBy<K>(right: Iterable<T>, keySelector: (element: T) => K, keyEqualer?: Equaler<K>): Query<T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
take(count)
Creates a subquery containing the first elements up to the supplied count.
Declaration
take(count: number): UnorderedQueryFlow<this, T>;
Parameters
Returns
takeRight(count)
Creates a subquery containing the last elements up to the supplied count.
Declaration
takeRight(count: number): UnorderedQueryFlow<this, T>;
Parameters
Returns
takeUntil(predicate)
Creates a subquery containing the first elements that do not match the supplied predicate.
Declaration
takeUntil(predicate: (element: T) => boolean): UnorderedQueryFlow<this, T>;
Parameters
- predicate
- (element: T) => boolean
A callback used to match each element.
Returns
takeWhile(predicate)
Creates a subquery containing the first elements that match the supplied predicate.
Declaration
takeWhile<U extends T>(predicate: (element: T) => element is U): UnorderedQueryFlow<this, U>;
Type Parameters
- U
Parameters
- predicate
- (element: T) => element is U
A callback used to match each element.
Returns
takeWhile(predicate)
Creates a subquery containing the first elements that match the supplied predicate.
Declaration
takeWhile(predicate: (element: T) => boolean): UnorderedQueryFlow<this, T>;
Parameters
- predicate
- (element: T) => boolean
A callback used to match each element.
Returns
tap(callback)
Lazily invokes a callback as each element of the Query
is iterated.
Declaration
tap(callback: (element: T, offset: number) => void): UnorderedQueryFlow<this, T>;
Parameters
- callback
- (element: T, offset: number) => void
The callback to invoke.
Returns
through(callback)
Pass the entire Query
to the provided callback, creating a new Query
from the result.
Declaration
through<R extends Iterable<any>>(callback: (source: this) => R): QueryFlow<R, R extends Iterable<infer U> ? U : unknown>;
Type Parameters
- R
Parameters
- callback
- (source: this) => R
A callback function.
Returns
toArray()
Creates an Array for the elements of the Query
.
Scalar
Declaration
toArray(): T[];
Returns
toArray(elementSelector)
Creates an Array for the elements of the Query
.
Declaration
toArray<V>(elementSelector: (element: T) => V): V[];
Type Parameters
- V
Parameters
- elementSelector
- (element: T) => V
A callback that selects a value for each element. Scalar
Returns
toHashMap(keySelector, keyEqualer)
Creates a Map
for the elements of the Query
.
Declaration
toHashMap<K>(keySelector: (element: T) => K, keyEqualer?: Equaler<K>): HashMap<K, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select a key for each element.
Returns
toHashMap(keySelector, elementSelector, keyEqualer)
Creates a Map
for the elements of the Query
.
Declaration
toHashMap<K, V>(keySelector: (element: T) => K, elementSelector: (element: T) => V, keyEqualer?: Equaler<K>): HashMap<K, V>;
Type Parameters
- K
- V
Parameters
- keySelector
- (element: T) => K
A callback used to select a key for each element.
- elementSelector
- (element: T) => V
A callback that selects a value for each element.
Returns
toHashSet(equaler)
Creates a HashSet
for the elements of the Query
.
Declaration
toHashSet(equaler?: Equaler<T>): HashSet<T>;
Parameters
Returns
toHashSet(elementSelector, equaler)
Creates a HashSet
for the elements of the Query
.
Declaration
toHashSet<V>(elementSelector: (element: T) => V, equaler?: Equaler<V>): HashSet<V>;
Type Parameters
- V
Parameters
- elementSelector
- (element: T) => V
A callback that selects a value for each element.
Returns
toHierarchy(provider)
Creates a HierarchyQuery
using the provided HierarchyProvider
.
Declaration
toHierarchy<TNode extends (T extends TNode ? unknown : never)>(provider: HierarchyProvider<TNode>): HierarchyQueryFlow<this, TNode, T>;
Type Parameters
- TNode
Parameters
Returns
toJSON()
Declaration
toJSON(): T[];
Returns
toLookup(keySelector, keyEqualer)
Creates a Lookup
for the elements of the Query
.
Declaration
toLookup<K>(keySelector: (element: T) => K, keyEqualer?: Equaler<K>): Lookup<K, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select a key for each element.
Returns
toLookup(keySelector, elementSelector, keyEqualer)
Creates a Lookup
for the elements of the Query
.
Declaration
toLookup<K, V>(keySelector: (element: T) => K, elementSelector: (element: T) => V, keyEqualer?: Equaler<K>): Lookup<K, V>;
Type Parameters
- K
- V
Parameters
- keySelector
- (element: T) => K
A callback used to select a key for each element.
- elementSelector
- (element: T) => V
A callback that selects a value for each element.
Returns
toMap(keySelector)
Creates a Map
for the elements of the Query
.
Declaration
toMap<K>(keySelector: (element: T) => K): Map<K, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select a key for each element. Scalar
Returns
toMap(keySelector, elementSelector)
Creates a Map
for the elements of the Query
.
Declaration
toMap<K, V>(keySelector: (element: T) => K, elementSelector: (element: T) => V): Map<K, V>;
Type Parameters
- K
- V
Parameters
- keySelector
- (element: T) => K
A callback used to select a key for each element.
- elementSelector
- (element: T) => V
A callback that selects a value for each element. Scalar
Returns
toObject(prototype, keySelector)
Creates an Object for the elements of the Query
. Properties are added via Object.defineProperty
.
// As a regular object
const obj = from(`"`, 1], ["y", 2]]).toObject(undefined, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // function
// with a custom prototype
const baseObject = { toString() { return `${this.x}:${this.y}` } };
const obj = from(`"`, 1], ["y", 2]]).toObject(baseObject, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // function
obj.toString(); // "x",1:"y",2
// with a null prototype
const obj = from(`"`, 1], ["y", 2]]).toObject(null, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // undefined
Declaration
toObject<TProto extends object, K extends PropertyKey>(prototype: TProto, keySelector: (element: T) => K): TProto & Record<K, T>;
Type Parameters
- TProto
- K
Parameters
- prototype
- TProto
The prototype for the object. If prototype
is null
, an object with a null
prototype is created. If prototype
is undefined
, the default Object.prototype
is used.
- keySelector
- (element: T) => K
A callback used to select a key for each element. Scalar
Returns
toObject(prototype, keySelector)
Creates an Object for the elements of the Query
. Properties are added via Object.defineProperty
.
// As a regular object
const obj = from(`"`, 1], ["y", 2]]).toObject(undefined, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // function
// with a custom prototype
const baseObject = { toString() { return `${this.x}:${this.y}` } };
const obj = from(`"`, 1], ["y", 2]]).toObject(baseObject, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // function
obj.toString(); // "x",1:"y",2
// with a null prototype
const obj = from(`"`, 1], ["y", 2]]).toObject(null, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // undefined
Declaration
toObject<TProto extends object>(prototype: TProto, keySelector: (element: T) => PropertyKey): TProto & Record<PropertyKey, T>;
Type Parameters
- TProto
Parameters
- prototype
- TProto
The prototype for the object. If prototype
is null
, an object with a null
prototype is created. If prototype
is undefined
, the default Object.prototype
is used.
- keySelector
- (element: T) => PropertyKey
A callback used to select a key for each element. Scalar
Returns
toObject(prototype, keySelector)
Creates an Object for the elements of the Query
. Properties are added via Object.defineProperty
.
// As a regular object
const obj = from(`"`, 1], ["y", 2]]).toObject(undefined, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // function
// with a custom prototype
const baseObject = { toString() { return `${this.x}:${this.y}` } };
const obj = from(`"`, 1], ["y", 2]]).toObject(baseObject, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // function
obj.toString(); // "x",1:"y",2
// with a null prototype
const obj = from(`"`, 1], ["y", 2]]).toObject(null, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // undefined
Declaration
toObject<K extends PropertyKey>(prototype: object | null | undefined, keySelector: (element: T) => K): Record<K, T>;
Type Parameters
- K
Parameters
- prototype
- object | null | undefined
The prototype for the object. If prototype
is null
, an object with a null
prototype is created. If prototype
is undefined
, the default Object.prototype
is used.
- keySelector
- (element: T) => K
A callback used to select a key for each element. Scalar
Returns
toObject(prototype, keySelector)
Creates an Object for the elements of the Query
. Properties are added via Object.defineProperty
.
// As a regular object
const obj = from(`"`, 1], ["y", 2]]).toObject(undefined, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // function
// with a custom prototype
const baseObject = { toString() { return `${this.x}:${this.y}` } };
const obj = from(`"`, 1], ["y", 2]]).toObject(baseObject, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // function
obj.toString(); // "x",1:"y",2
// with a null prototype
const obj = from(`"`, 1], ["y", 2]]).toObject(null, a => a[0]);
obj.x; // ["x", 1]
obj.y; // ["y", 2]
typeof obj.toString; // undefined
Declaration
toObject(prototype: object | null | undefined, keySelector: (element: T) => PropertyKey): Record<PropertyKey, T>;
Parameters
- prototype
- object | null | undefined
The prototype for the object. If prototype
is null
, an object with a null
prototype is created. If prototype
is undefined
, the default Object.prototype
is used.
- keySelector
- (element: T) => PropertyKey
A callback used to select a key for each element. Scalar
Returns
toObject(prototype, keySelector, elementSelector, descriptorSelector)
Creates an Object for the elements the Query
. Properties are added via Object.defineProperty
.
// As a regular object
const obj = from(`"`, 1], ["y", 2]]).toObject(undefined, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // function
// with a custom prototype
const baseObject = { toString() { return `${this.x}:${this.y}` } };
const obj = from(`"`, 1], ["y", 2]]).toObject(baseObject, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // function
obj.toString(); // 1:2
// with a null prototype
const obj = from(`"`, 1], ["y", 2]]).toObject(null, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // undefined
Declaration
toObject<TProto extends object, K extends PropertyKey, V>(prototype: TProto, keySelector: (element: T) => K, elementSelector: (element: T) => V, descriptorSelector?: (key: K, element: V) => TypedPropertyDescriptor<V>): TProto & Record<K, V>;
Type Parameters
- TProto
- K
- V
Parameters
- prototype
- TProto
The prototype for the object. If prototype
is null
, an object with a null
prototype is created. If prototype
is undefined
, the default Object.prototype
is used.
- keySelector
- (element: T) => K
A callback used to select a key for each element.
- elementSelector
- (element: T) => V
A callback that selects a value for each element.
- descriptorSelector
- (key: K, element: V) => TypedPropertyDescriptor<V>
A callback that defines the PropertyDescriptor
for each property.
Scalar
Returns
toObject(prototype, keySelector, elementSelector, descriptorSelector)
Creates an Object for the elements the Query
. Properties are added via Object.defineProperty
.
// As a regular object
const obj = from(`"`, 1], ["y", 2]]).toObject(undefined, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // function
// with a custom prototype
const baseObject = { toString() { return `${this.x}:${this.y}` } };
const obj = from(`"`, 1], ["y", 2]]).toObject(baseObject, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // function
obj.toString(); // 1:2
// with a null prototype
const obj = from(`"`, 1], ["y", 2]]).toObject(null, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // undefined
Declaration
toObject<TProto extends object, V>(prototype: TProto, keySelector: (element: T) => PropertyKey, elementSelector: (element: T) => V, descriptorSelector?: (key: PropertyKey, element: V) => TypedPropertyDescriptor<V>): TProto & Record<PropertyKey, V>;
Type Parameters
- TProto
- V
Parameters
- prototype
- TProto
The prototype for the object. If prototype
is null
, an object with a null
prototype is created. If prototype
is undefined
, the default Object.prototype
is used.
- keySelector
- (element: T) => PropertyKey
A callback used to select a key for each element.
- elementSelector
- (element: T) => V
A callback that selects a value for each element.
- descriptorSelector
- (key: PropertyKey, element: V) => TypedPropertyDescriptor<V>
A callback that defines the PropertyDescriptor
for each property.
Scalar
Returns
toObject(prototype, keySelector, elementSelector, descriptorSelector)
Creates an Object for the elements the Query
. Properties are added via Object.defineProperty
.
// As a regular object
const obj = from(`"`, 1], ["y", 2]]).toObject(undefined, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // function
// with a custom prototype
const baseObject = { toString() { return `${this.x}:${this.y}` } };
const obj = from(`"`, 1], ["y", 2]]).toObject(baseObject, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // function
obj.toString(); // 1:2
// with a null prototype
const obj = from(`"`, 1], ["y", 2]]).toObject(null, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // undefined
Declaration
toObject<K extends PropertyKey, V>(prototype: object | null | undefined, keySelector: (element: T) => K, elementSelector: (element: T) => V, descriptorSelector?: (key: K, element: V) => TypedPropertyDescriptor<V>): Record<K, V>;
Type Parameters
- K
- V
Parameters
- prototype
- object | null | undefined
The prototype for the object. If prototype
is null
, an object with a null
prototype is created. If prototype
is undefined
, the default Object.prototype
is used.
- keySelector
- (element: T) => K
A callback used to select a key for each element.
- elementSelector
- (element: T) => V
A callback that selects a value for each element.
- descriptorSelector
- (key: K, element: V) => TypedPropertyDescriptor<V>
A callback that defines the PropertyDescriptor
for each property.
Scalar
Returns
toObject(prototype, keySelector, elementSelector, descriptorSelector)
Creates an Object for the elements the Query
. Properties are added via Object.defineProperty
.
// As a regular object
const obj = from(`"`, 1], ["y", 2]]).toObject(undefined, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // function
// with a custom prototype
const baseObject = { toString() { return `${this.x}:${this.y}` } };
const obj = from(`"`, 1], ["y", 2]]).toObject(baseObject, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // function
obj.toString(); // 1:2
// with a null prototype
const obj = from(`"`, 1], ["y", 2]]).toObject(null, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // undefined
Declaration
toObject<V>(prototype: object | null | undefined, keySelector: (element: T) => PropertyKey, elementSelector: (element: T) => V, descriptorSelector?: (key: PropertyKey, element: V) => TypedPropertyDescriptor<V>): Record<PropertyKey, V>;
Type Parameters
- V
Parameters
- prototype
- object | null | undefined
The prototype for the object. If prototype
is null
, an object with a null
prototype is created. If prototype
is undefined
, the default Object.prototype
is used.
- keySelector
- (element: T) => PropertyKey
A callback used to select a key for each element.
- elementSelector
- (element: T) => V
A callback that selects a value for each element.
- descriptorSelector
- (key: PropertyKey, element: V) => TypedPropertyDescriptor<V>
A callback that defines the PropertyDescriptor
for each property.
Scalar
Returns
toObject(prototype, keySelector, elementSelector, descriptorSelector)
Creates an Object for the elements the Query
. Properties are added via Object.defineProperty
.
// As a regular object
const obj = from(`"`, 1], ["y", 2]]).toObject(undefined, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // function
// with a custom prototype
const baseObject = { toString() { return `${this.x}:${this.y}` } };
const obj = from(`"`, 1], ["y", 2]]).toObject(baseObject, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // function
obj.toString(); // 1:2
// with a null prototype
const obj = from(`"`, 1], ["y", 2]]).toObject(null, a => a[0], a => a[1]);
obj.x; // 1
obj.y; // 2
typeof obj.toString; // undefined
Declaration
toObject<V>(prototype: object | null | undefined, keySelector: (element: T) => PropertyKey, elementSelector: (element: T) => V, descriptorSelector?: (key: PropertyKey, element: V) => PropertyDescriptor): object;
Type Parameters
- V
Parameters
- prototype
- object | null | undefined
The prototype for the object. If prototype
is null
, an object with a null
prototype is created. If prototype
is undefined
, the default Object.prototype
is used.
- keySelector
- (element: T) => PropertyKey
A callback used to select a key for each element.
- elementSelector
- (element: T) => V
A callback that selects a value for each element.
- descriptorSelector
- (key: PropertyKey, element: V) => PropertyDescriptor
A callback that defines the PropertyDescriptor
for each property.
Scalar
Returns
toSet()
Creates a Set
for the elements of the Query
.
Scalar
Declaration
toSet(): Set<T>;
Returns
toSet(elementSelector)
Creates a Set
for the elements of the Query
.
Declaration
toSet<V>(elementSelector: (element: T) => V): Set<V>;
Type Parameters
- V
Parameters
- elementSelector
- (element: T) => V
A callback that selects a value for each element. Scalar
Returns
union(right, equaler)
Creates a subquery for the set union of this Query
and another Iterable
.
Declaration
union<R extends Iterable<T>>(right: R, equaler?: Equaler<T>): MergeQueryFlow<this, R, T>;
Type Parameters
- R
Parameters
- right
- R
A Iterable
object.
Returns
union(right, equaler)
Creates a subquery for the set union of this Query
and another Iterable
.
Declaration
union(right: Iterable<T>, equaler?: Equaler<T>): Query<T>;
Parameters
Returns
unionBy(right, keySelector, keyEqualer)
Creates a subquery for the set union of this Query
and another Iterable
, where set identity is determined by the selected key.
Declaration
unionBy<K, R extends Iterable<T>>(right: R, keySelector: (element: T) => K, keyEqualer?: Equaler<K>): MergeQueryFlow<this, R, T>;
Type Parameters
- K
- R
Parameters
- right
- R
A Iterable
object.
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
unionBy(right, keySelector, keyEqualer)
Creates a subquery for the set union of this Query
and another Iterable
, where set identity is determined by the selected key.
Declaration
unionBy<K>(right: Iterable<T>, keySelector: (element: T) => K, keyEqualer?: Equaler<K>): Query<T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
unzip()
Unzips a sequence of tuples into a tuple of sequences.
Declaration
unzip(): T extends [any, ...any[]] ? {
[I in keyof T]: T[I][];
} : unknown[];
Returns
unzip(partSelector)
Unzips a sequence of tuples into a tuple of sequences.
Declaration
unzip<U extends [any, ...any[]]>(partSelector: (value: T) => U): {
[I in keyof U]: U[I][];
};
Type Parameters
- U
Parameters
- partSelector
- (value: T) => U
A callback that converts a result into a tuple. Scalar
Returns
where(predicate)
Creates a subquery whose elements match the supplied predicate.
NOTE: This is an alias for filter
.
Declaration
where<U extends T>(predicate: (element: T, offset: number) => element is U): UnorderedQueryFlow<this, U>;
Type Parameters
- U
Parameters
- predicate
- (element: T, offset: number) => element is U
A callback used to match each element.
Returns
where(predicate)
Creates a subquery whose elements match the supplied predicate.
NOTE: This is an alias for filter
.
Declaration
where(predicate: (element: T, offset: number) => boolean): UnorderedQueryFlow<this, T>;
Parameters
- predicate
- (element: T, offset: number) => boolean
A callback used to match each element.
Returns
whereBy(keySelector, predicate)
Creates a subquery where the selected key for each element matches the supplied predicate.
NOTE: This is an alias for filterBy
.
Declaration
whereBy<K>(keySelector: (element: T) => K, predicate: (key: K, offset: number) => boolean): UnorderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
- predicate
- (key: K, offset: number) => boolean
A callback used to match each key.
Returns
whereDefined()
Creates a subquery whose elements are neither null
nor undefined
.
NOTE: This is an alias for filterDefined
.
Subquery
Declaration
whereDefined(): UnorderedQueryFlow<this, NonNullable<T>>;
Returns
whereDefinedBy(keySelector)
Creates a subquery where the selected key for each element is neither null
nor undefined
.
NOTE: This is an alias for filterDefinedBy
.
Declaration
whereDefinedBy<K>(keySelector: (element: T) => K): UnorderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
whereNot(predicate)
Creates a subquery whose elements do not match the supplied predicate.
NOTE: This is an alias for filterNot
.
Declaration
whereNot<U extends T>(predicate: (element: T, offset: number) => element is U): UnorderedQueryFlow<this, U>;
Type Parameters
- U
Parameters
- predicate
- (element: T, offset: number) => element is U
A callback used to match each element.
Returns
whereNot(predicate)
Creates a subquery whose elements do not match the supplied predicate.
NOTE: This is an alias for filterNot
.
Declaration
whereNot(predicate: (element: T, offset: number) => boolean): UnorderedQueryFlow<this, T>;
Parameters
- predicate
- (element: T, offset: number) => boolean
A callback used to match each element.
Returns
whereNotBy(keySelector, predicate)
Creates a subquery where the selected key for each element does not match the supplied predicate.
NOTE: This is an alias for filterNotBy
.
Declaration
whereNotBy<K>(keySelector: (element: T) => K, predicate: (key: K, offset: number) => boolean): UnorderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
- predicate
- (key: K, offset: number) => boolean
A callback used to match each key.
Returns
whereNotDefinedBy(keySelector)
Creates a subquery where the selected key for each element is either null
or undefined
.
NOTE: This is an alias for filterNotDefinedBy
.
Declaration
whereNotDefinedBy<K>(keySelector: (element: T) => K): UnorderedQueryFlow<this, T>;
Type Parameters
- K
Parameters
- keySelector
- (element: T) => K
A callback used to select the key for each element.
Returns
zip(right)
Creates a subquery that combines this Query
with another Iterable
by combining elements
in tuples.
Declaration
zip<U>(right: Iterable<U>): Query<[T, U]>;
Type Parameters
- U
Parameters
Returns
zip(right, selector)
Creates a subquery that combines this Query
with another Iterable
by combining elements
using the supplied callback.
Declaration
zip<U, R>(right: Iterable<U>, selector: (left: T, right: U) => R): Query<R>;
Type Parameters
- U
- R
Parameters
- selector
- (left: T, right: U) => R
A callback used to combine two elements. Join
Returns