/*! Copyright 2018 Ron Buckton (rbuckton@chronicles.org) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /** @module "iterable-query" */ import { Comparison, Comparer, EqualityComparison, Equaler } from '@esfx/equatable'; import { HashMap } from '@esfx/collections-hashmap'; import { HashSet } from '@esfx/collections-hashset'; import { OrderedHierarchyIterable, HierarchyIterable, OrderedIterable, Queryable, HierarchyProvider, Hierarchical, Grouping, KeyValuePair, Page, Choice, QueriedType, WritableArrayLike } from "./types"; import { Lookup } from "./lookup"; import { ConsumeOptions } from "./fn"; /** * Flows the base type of a [[Query]] as an unordered query with a new iterated type. */ export declare type UnorderedQueryFlow, T> = S extends Hierarchical ? HierarchyQuery : Query; /** * Flows the base type of a [[Query]] as an ordered query with a new iterated type. */ export declare type OrderedQueryFlow, T> = S extends Hierarchical ? OrderedHierarchyQuery : OrderedQuery; /** * Flows the base type of a [[Query]] as a hierarchical query with a new iterated type. */ export declare type HierarchyQueryFlow, T> = S extends OrderedIterable ? OrderedHierarchyQuery : HierarchyQuery; /** * Flows the base type of a [[Query]] with a new iterated type. */ export declare type QueryFlow, T> = S extends OrderedIterable ? OrderedQueryFlow : UnorderedQueryFlow; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source An [[OrderedHierarchyIterable]] object. */ export declare function from(source: OrderedHierarchyIterable): OrderedHierarchyQuery; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source A [[HierarchyIterable]] object. */ export declare function from(source: HierarchyIterable): HierarchyQuery; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source An [[OrderedIterable]] object. */ export declare function from(source: OrderedIterable): OrderedQuery; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source A [[Queryable]] object. */ export declare function from(source: Queryable): Query; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source An [[OrderedIterable]] object. * @param hierarchy A [[HierarchyProvider]] object. */ export declare function from(source: OrderedIterable, hierarchy: HierarchyProvider): OrderedHierarchyQuery; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source A [[Queryable]] object. * @param hierarchy A [[HierarchyProvider]] object. */ export declare function from(source: Queryable, hierarchy: HierarchyProvider): HierarchyQuery; /** * 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. * * @typeparam T The type for each element. */ export declare class Query implements Iterable { private _source; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source A [[Queryable]] object. */ constructor(source: Queryable); /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source An [[OrderedHierarchyIterable]] object. * @category Query */ static from(source: OrderedHierarchyIterable): OrderedHierarchyQuery; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source A [[HierarchyIterable]] object. * @category Query */ static from(source: HierarchyIterable): HierarchyQuery; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source An [[OrderedIterable]] object. * @category Query */ static from(source: OrderedIterable): OrderedQuery; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source A [[Queryable]] object. * @category Query */ static from(source: Queryable): Query; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source A [[Queryable]] object. * @param hierarchy A [[HierarchyProvider]] object. * @category Query */ static from(source: OrderedIterable, hierarchy: HierarchyProvider): OrderedHierarchyQuery; /** * Creates a [[Query]] from a [[Queryable]] source. * * @param source A [[Queryable]] object. * @param hierarchy A [[HierarchyProvider]] object. * @category Query */ static from(source: Queryable, hierarchy: HierarchyProvider): HierarchyQuery; /** * Creates a [[Query]] for the provided elements. * * @param elements The elements of the [[Query]]. * @category Query */ static of(...elements: T[]): Query; /** * Creates a [[Query]] with no elements. * * @category Query */ static empty(): Query; /** * Creates a [[Query]] over a single element. * * @param value The only element for the [[Query]]. * @category Query */ static once(value: T): Query; /** * Creates a [[Query]] for a value repeated a provided number of times. * * @param value The value for each element of the [[Query]]. * @param count The number of times to repeat the value. * @category Query */ static repeat(value: T, count: number): Query; /** * Creates a [[Query]] over a range of numbers. * * @param start The starting number of the range. * @param end The ending number of the range. * @param increment The amount by which to change between each itereated value. * @category Query */ static range(start: number, end: number, increment?: number): Query; /** * Creates a [[Query]] that repeats the provided value forever. * * @param value The value for each element of the [[Query]]. * @category Query */ static continuous(value: T): Query; /** * Creates a [[Query]] whose values are provided by a callback executed a provided number of * times. * * @param count The number of times to execute the callback. * @param generator The callback to execute. * @category Query */ static generate(count: number, generator: (offset: number) => T): Query; /** * Creates a HierarchyQuery from a root node and a HierarchyProvider. * * @param root The root node of the hierarchy. * @param hierarchy A [[HierarchyProvider]] object. * @category Query */ static hierarchy(root: T, hierarchy: HierarchyProvider): HierarchyQuery; /** * Creates a [[Query]] that, when iterated, consumes the provided `Iterator`. * * @param iterator An `Iterator` object. * @category Query */ static consume(iterator: Iterator, options?: ConsumeOptions): Query; /** * Creates a [[Query]] that iterates the elements from one of two sources based on the result of a * lazily evaluated condition. * * @param condition A callback used to choose a source. * @param thenQueryable The source to use when the callback evaluates to `true`. * @param elseQueryable The source to use when the callback evaluates to `false`. * @category Query */ static if(condition: () => boolean, thenQueryable: Queryable, elseQueryable?: Queryable): Query; /** * Creates a [[Query]] that iterates the elements from sources picked from a list based on the * result of a lazily evaluated choice. * * @param chooser A callback used to choose a source. * @param choices A list of sources * @param otherwise A default source to use when another choice could not be made. * @category Query */ static choose(chooser: () => K, choices: Queryable>, otherwise?: Queryable): Query; /** * Creates a [[Query]] for the own property keys of an object. * * @param source An object. * @category Query */ static objectKeys(source: T): Query>; /** * Creates a [[Query]] for the own property values of an object. * * @param source An object. * @category Query */ static objectValues(source: T): Query]>; /** * Creates a [[Query]] for the own property key-value pairs of an object. * * @param source An object. * @category Query */ static objectEntries(source: T): Query>>; /** * Creates a subquery whose elements match the supplied predicate. * * @param predicate A callback used to match each element. * @param predicate.element The element to test. * @param predicate.offset The offset from the start of the source iterable. * @category Subquery */ filter(predicate: (element: T, offset: number) => element is U): UnorderedQueryFlow; /** * Creates a subquery whose elements match the supplied predicate. * * @param predicate A callback used to match each element. * @param predicate.element The element to test. * @param predicate.offset The offset from the start of the source iterable. * @category Subquery */ filter(predicate: (element: T, offset: number) => boolean): UnorderedQueryFlow; /** * Creates a subquery where the selected key for each element matches the supplied predicate. * * @param keySelector A callback used to select the key for each element. * @param keySelector.element The element from which to select a key. * @param predicate A callback used to match each key. * @param predicate.key The key to test. * @param predicate.offset The offset from the start of the source iterable. * @category Subquery */ filterBy(keySelector: (element: T) => K, predicate: (key: K, offset: number) => boolean): UnorderedQueryFlow; /** * Creates a subquery whose elements are neither `null` nor `undefined`. * * @category Subquery */ filterDefined(): UnorderedQueryFlow>; /** * Creates a subquery where the selected key for each element is neither `null` nor `undefined`. * * @param keySelector A callback used to select the key for each element. * @param keySelector.element The element from which to select a key. * @category Subquery */ filterDefined(keySelector: (element: T) => K): UnorderedQueryFlow; /** * Creates a subquery whose elements match the supplied predicate. * * NOTE: This is an alias for [[filter]]. * * @param predicate A callback used to match each element. * @param predicate.element The element to test. * @param predicate.offset The offset from the start of the source iterable. * @category Subquery */ where(predicate: (element: T, offset: number) => element is U): UnorderedQueryFlow; /** * Creates a subquery whose elements match the supplied predicate. * * NOTE: This is an alias for [[filter]]. * * @param predicate A callback used to match each element. * @param predicate.element The element to test. * @param predicate.offset The offset from the start of the source iterable. * @category Subquery */ where(predicate: (element: T, offset: number) => boolean): UnorderedQueryFlow; /** * Creates a subquery where the selected key for each element matches the supplied predicate. * * NOTE: This is an alias for [[filterBy]]. * * @param keySelector A callback used to select the key for each element. * @param keySelector.element The element from which to select a key. * @param predicate A callback used to match each key. * @param predicate.key The key to test. * @param predicate.offset The offset from the start of the source iterable. * @category Subquery */ whereBy(keySelector: (element: T) => K, predicate: (key: K, offset: number) => boolean): UnorderedQueryFlow; /** * Creates a subquery whose elements are neither `null` nor `undefined`. * * NOTE: This is an alias for [[filterDefined]]. * * @category Subquery */ whereDefined(): UnorderedQueryFlow>; /** * Creates a subquery where the selected key for each element is neither `null` nor `undefined`. * * NOTE: This is an alias for [[filterDefined]]. * * @param keySelector A callback used to select the key for each element. * @param keySelector.element The element from which to select a key. * @category Subquery */ whereDefined(keySelector: (element: T) => K): UnorderedQueryFlow; /** * Creates a subquery by applying a callback to each element. * * @param selector A callback used to map each element. * @param selector.element The element to map. * @param selector.offset The offset from the start of the source iterable. * @category Subquery */ map(selector: (element: T, offset: number) => U): Query; /** * Creates a subquery by applying a callback to each element. * * NOTE: This is an alias for [[map]]. * * @param selector A callback used to map each element. * @param selector.element The element to map. * @param selector.offset The offset from the start of the source [[Queryable]]. * @category Subquery */ select(selector: (element: T, offset: number) => U): Query; /** * Creates a subquery that iterates the results of applying a callback to each element. * * @param projection A callback used to map each element into a [[Queryable]]. * @param projection.element The element to map. * @category Subquery */ flatMap(projection: (element: T) => Queryable): Query; /** * Creates a subquery that iterates the results of applying a callback to each element. * * @param projection A callback used to map each element into a [[Queryable]]. * @param projection.element The outer element to map. * @param resultSelector An optional callback used to map the outer and projected inner elements. * @param resultSelector.element The outer element to map. * @param resultSelector.innerElement An inner element produced by the `projection` of the outer element. * @category Subquery */ flatMap(projection: (element: T) => Queryable, resultSelector: (element: T, innerElement: U) => R): Query; /** * Creates a subquery that iterates the results of applying a callback to each element. * * NOTE: This is an alias for [[flatMap]]. * * @param projection A callback used to map each element into an iterable. * @param projection.element The element to map. * @category Subquery */ selectMany(projection: (element: T) => Queryable): Query; /** * Creates a subquery that iterates the results of applying a callback to each element. * * NOTE: This is an alias for [[flatMap]]. * * @param projection A callback used to map each element into an iterable. * @param projection.element The element to map. * @param resultSelector An optional callback used to map the outer and projected inner elements. * @param resultSelector.element The outer element to map. * @param resultSelector.innerElement An inner element produced by the `projection` of the outer element. * @category Subquery */ selectMany(projection: (element: T) => Queryable, resultSelector: (element: T, innerElement: U) => R): Query; /** * Creates a subquery that iterates the results of recursively expanding the * elements of the source. * * @param projection A callback used to recusively expand each element. * @param projection.element The element to expand. * @category Subquery */ expand(projection: (element: T) => Queryable): Query; /** * Lazily invokes a callback as each element of the [[Query]] is iterated. * * @param callback The callback to invoke. * @param callback.element An element of the source. * @param callback.offset The offset from the start of the source iterable. * @category Subquery */ do(callback: (element: T, offset: number) => void): UnorderedQueryFlow; /** * Lazily invokes a callback as each element of the [[Query]] is iterated. * * NOTE: This is an alias for [[do]]. * * @param callback The callback to invoke. * @param callback.element An element of the source. * @param callback.offset The offset from the start of the source iterable. * @category Subquery */ tap(callback: (element: T, offset: number) => void): UnorderedQueryFlow; /** * Creates a subquery whose elements are in the reverse order. * * @category Subquery */ reverse(): UnorderedQueryFlow; /** * Creates a subquery with every instance of the specified value removed. * * @param values The values to exclude. * @category Subquery */ exclude(...values: [T, ...T[]]): UnorderedQueryFlow; /** * Creates a subquery containing all elements except the first elements up to the supplied * count. * * @param count The number of elements to skip. * @category Subquery */ skip(count: number): UnorderedQueryFlow; /** * Creates a subquery containing all elements except the last elements up to the supplied * count. * * @param count The number of elements to skip. * @category Subquery */ skipRight(count: number): UnorderedQueryFlow; /** * Creates a subquery containing all elements except the first elements that match * the supplied predicate. * * @param predicate A callback used to match each element. * @param predicate.element The element to match. * @category Subquery */ skipWhile(predicate: (element: T) => boolean): UnorderedQueryFlow; /** * Creates a subquery containing all elements except the first elements that don't match * the supplied predicate. * * @param predicate A callback used to match each element. * @param predicate.element The element to match. * @category Subquery */ skipUntil(predicate: (element: T) => boolean): UnorderedQueryFlow; /** * Creates a subquery containing the first elements up to the supplied * count. * * @param count The number of elements to take. * @category Subquery */ take(count: number): UnorderedQueryFlow; /** * Creates a subquery containing the last elements up to the supplied * count. * * @param count The number of elements to take. * @category Subquery */ takeRight(count: number): UnorderedQueryFlow; /** * Creates a subquery containing the first elements that match the supplied predicate. * * @param predicate A callback used to match each element. * @param predicate.element The element to match. * @category Subquery */ takeWhile(predicate: (element: T) => element is U): UnorderedQueryFlow; /** * Creates a subquery containing the first elements that match the supplied predicate. * * @param predicate A callback used to match each element. * @param predicate.element The element to match. */ takeWhile(predicate: (element: T) => boolean): UnorderedQueryFlow; /** * Creates a subquery containing the first elements that do not match the supplied predicate. * * @param predicate A callback used to match each element. * @param predicate.element The element to match. * @category Subquery */ takeUntil(predicate: (element: T) => boolean): UnorderedQueryFlow; /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler An [[Equaler]] object used to compare equality. * @category Subquery */ intersect(right: HierarchyIterable, equaler?: Equaler): HierarchyQuery; /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler An [[Equaler]] object used to compare equality. * @category Subquery */ intersect(right: Queryable, equaler?: Equaler): Query; /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler An [[Equaler]] object used to compare equality. * @category Subquery */ intersect(right: Queryable, equaler?: Equaler): Query; /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]], where set identity is determined by the selected key. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ intersectBy(right: HierarchyIterable, keySelector: (element: T) => K, keyEqualer?: Equaler): HierarchyQuery; /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]], where set identity is determined by the selected key. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ intersectBy(right: Queryable, keySelector: (element: T) => K, keyEqualer?: Equaler): Query; /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]], where set identity is determined by the selected key. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ intersectBy(right: Queryable, keySelector: (element: T) => K, keyEqualer?: Equaler): Query; /** * Creates a subquery for the set union of this [[Query]] and another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler An [[Equaler]] object used to compare equality. * @category Subquery */ union(right: Queryable, equaler?: Equaler): UnorderedQueryFlow; /** * Creates a subquery for the set union of this [[Query]] and another [[Queryable]], where set identity is determined by the selected key. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ unionBy(right: Queryable, keySelector: (element: T) => K, keyEqualer?: Equaler): UnorderedQueryFlow; /** * Creates a subquery for the set difference between this and another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler An [[Equaler]] object used to compare equality. * @category Subquery */ except(right: Queryable, equaler?: Equaler): UnorderedQueryFlow; /** * Creates a subquery for the set difference between this and another [[Queryable]], where set identity is determined by the selected key. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ exceptBy(right: Queryable, keySelector: (element: T) => K, keyEqualer?: Equaler): UnorderedQueryFlow; /** * Creates a subquery for the set difference between this and another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler An [[Equaler]] object used to compare equality. * @category Subquery */ relativeComplement(right: Queryable, equaler?: Equaler): UnorderedQueryFlow; /** * Creates a subquery for the set difference between this and another [[Queryable]], where set identity is determined by the selected key. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ relativeComplementBy(right: Queryable, keySelector: (element: T) => K, keyEqualer?: Equaler): UnorderedQueryFlow; /** * Creates a subquery for the symmetric difference between this and another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler An [[Equaler]] object used to compare equality. * @category Subquery */ symmetricDifference(right: Queryable, equaler?: Equaler): UnorderedQueryFlow; /** * Creates a subquery for the symmetric difference between this and another [[Queryable]], where set identity is determined by the selected key. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ symmetricDifferenceBy(right: Queryable, keySelector: (element: T) => K, keyEqualer?: Equaler): UnorderedQueryFlow; /** * Creates a subquery for the symmetric difference between this and another [[Queryable]]. * * NOTE: This is an alias for [[symmetricDifference]]. * * @param right A [[Queryable]] object. * @param equaler An [[Equaler]] object used to compare equality. * @category Subquery */ xor(right: Queryable, equaler?: Equaler): UnorderedQueryFlow; /** * Creates a subquery for the symmetric difference between this and another [[Queryable]], where set identity is determined by the selected key. * * NOTE: This is an alias for [[symmetricDifferenceBy]]. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ xorBy(right: Queryable, keySelector: (element: T) => K, keyEqualer?: Equaler): UnorderedQueryFlow; /** * Creates a subquery that concatenates this [[Query]] with another [[Queryable]]. * * @param right A [[Queryable]] object. * @category Subquery */ concat(right: Queryable): UnorderedQueryFlow; /** * Creates a subquery for the distinct elements of this [[Query]]. * @param equaler An [[Equaler]] object used to compare key equality. * @category Subquery */ distinct(equaler?: Equaler): UnorderedQueryFlow; /** * Creates a subquery for the distinct elements of this [[Query]]. * * @param keySelector A callback used to select the key to determine uniqueness. * @param keySelector.value An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ distinctBy(keySelector: (value: T) => K, keyEqualer?: Equaler): UnorderedQueryFlow; /** * Creates a subquery for the elements of this [[Query]] with the provided value appended to the end. * * @param value The value to append. * @category Subquery */ append(value: T): UnorderedQueryFlow; /** * Creates a subquery for the elements of this [[Query]] with the provided value prepended to the beginning. * * @param value The value to prepend. * @category Subquery */ prepend(value: T): UnorderedQueryFlow; /** * Creates a subquery for the elements of this [[Query]] with the provided range * patched into the results. * * @param start The offset at which to patch the range. * @param skipCount The number of elements to skip from start. * @param range The range to patch into the result. * @category Subquery */ patch(start: number, skipCount?: number, range?: Queryable): UnorderedQueryFlow; /** * Creates a subquery that contains the provided default value if this [[Query]] * contains no elements. * * @param defaultValue The default value. * @category Subquery */ defaultIfEmpty(defaultValue: T): UnorderedQueryFlow; /** * 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. * * @param pageSize The number of elements per page. * @category Subquery */ pageBy(pageSize: number): Query>; /** * Creates a subquery whose elements are the contiguous ranges of elements that share the same key. * * @param keySelector A callback used to select the key for an element. * @param keySelector.element An element from which to select a key. * @category Subquery */ spanMap(keySelector: (element: T) => K): Query>; /** * Creates a subquery whose values are computed from each element of the contiguous ranges of elements that share the same key. * * @param keySelector A callback used to select the key for an element. * @param keySelector.element An element from which to select a key. * @param elementSelector A callback used to select a value for an element. * @param elementSelector.element An element from which to select a value. * @category Subquery */ spanMap(keySelector: (element: T) => K, elementSelector: (element: T) => V): Query>; /** * Creates a subquery whose values are computed from the contiguous ranges of elements that share the same key. * * @param keySelector A callback used to select the key for an element. * @param keySelector.element An element from which to select a key. * @param elementSelector A callback used to select a value for an element. * @param elementSelector.element An element from which to select a value. * @param spanSelector A callback used to select a result from a contiguous range. * @param spanSelector.key The key for the span. * @param spanSelector.elements The elements for the span. * @category Subquery */ spanMap(keySelector: (element: T) => K, elementSelector: (element: T) => V, spanSelector: (key: K, elements: Query) => R): Query; /** * Groups each element of this [[Query]] by its key. * * @param keySelector A callback used to select the key for an element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ groupBy(keySelector: (element: T) => K, keyEqualer?: Equaler): Query>; /** * Groups each element by its key. * * @param keySelector A callback used to select the key for an element. * @param keySelector.element An element from which to select a key. * @param elementSelector A callback used to select a value for an element. * @param elementSelector.element An element from which to select a value. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ groupBy(keySelector: (element: T) => K, elementSelector: (element: T) => V, keyEqualer?: Equaler): Query>; /** * Groups each element by its key. * * @param keySelector A callback used to select the key for an element. * @param keySelector.element An element from which to select a key. * @param elementSelector A callback used to select a value for an element. * @param elementSelector.element An element from which to select a value. * @param resultSelector A callback used to select a result from a group. * @param resultSelector.key The key for the group. * @param resultSelector.elements The elements for the group. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ groupBy(keySelector: (element: T) => K, elementSelector: (element: T) => V, resultSelector: (key: K, elements: Query) => R, keyEqualer?: Equaler): Query; /** * Creates a subquery containing the cumulative results of applying the provided callback to each element. * * @param accumulator The callback used to compute each result. * @param accumulator.current The current accumulated value. * @param accumulator.element The value to accumulate. * @param accumulator.offset The offset from the start of the underlying [[Queryable]]. * @category Subquery */ scan(accumulator: (current: T, element: T, offset: number) => T): Query; /** * Creates a subquery containing the cumulative results of applying the provided callback to each element. * * @param accumulator The callback used to compute each result. * @param accumulator.current The current accumulated value. * @param accumulator.element The value to accumulate. * @param accumulator.offset The offset from the start of the underlying [[Queryable]]. * @param seed An optional seed value. * @category Subquery */ scan(accumulator: (current: U, element: T, offset: number) => U, seed: U): Query; /** * Creates a subquery containing the cumulative results of applying the provided callback to each element in reverse. * * @param accumulator The callback used to compute each result. * @param accumulator.current The current accumulated value. * @param accumulator.element The value to accumulate. * @param accumulator.offset The offset from the start of the underlying [[Queryable]]. * @category Subquery */ scanRight(accumulator: (current: T, element: T, offset: number) => T): Query; /** * Creates a subquery containing the cumulative results of applying the provided callback to each element in reverse. * * @param accumulator The callback used to compute each result. * @param accumulator.current The current accumulated value. * @param accumulator.element The value to accumulate. * @param accumulator.offset The offset from the start of the underlying [[Queryable]]. * @param seed An optional seed value. * @category Subquery */ scanRight(accumulator: (current: U, element: T, offset: number) => U, seed?: U): Query; /** * Pass the entire [[Query]] to the provided callback, creating a new [[Query]] from the result. * * @param callback A callback function. * @param callback.source The outer [[Query]]. * @category Subquery */ through = Queryable>(callback: (source: this) => R): QueryFlow>; /** * Creates a grouped subquery for the correlated elements of this [[Query]] and another [[Queryable]] object. * * @param inner A [[Queryable]] object. * @param outerKeySelector A callback used to select the key for an element in this [[Query]]. * @param innerKeySelector A callback used to select the key for an element in the other [[Queryable]] object. * @param resultSelector A callback used to select the result for the correlated elements. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Join */ groupJoin(inner: Queryable, outerKeySelector: (element: T) => K, innerKeySelector: (element: I) => K, resultSelector: (outer: T, inner: Query) => R, keyEqualer?: Equaler): Query; /** * Creates a subquery for the correlated elements of this [[Query]] and another [[Queryable]]. * * @param inner A [[Queryable]] object. * @param outerKeySelector A callback used to select the key for an element in this [[Query]]. * @param innerKeySelector A callback used to select the key for an element in the other Queryable. * @param resultSelector A callback used to select the result for the correlated elements. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Join */ join(inner: Queryable, outerKeySelector: (element: T) => K, innerKeySelector: (element: I) => K, resultSelector: (outer: T, inner: I) => R, keyEqualer?: Equaler): Query; /** * Creates a subquery for the correlated elements of this [[Query]] and another [[Queryable]]. * * @param inner A [[Queryable]] object. * @param outerKeySelector A callback used to select the key for an element in this [[Query]]. * @param innerKeySelector A callback used to select the key for an element in the other Queryable. * @param resultSelector A callback used to select the result for the correlated elements. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Join */ fullJoin(inner: Queryable, outerKeySelector: (element: T) => K, innerKeySelector: (element: I) => K, resultSelector: (outer: T | undefined, inner: I | undefined) => R, keyEqualer?: Equaler): Query; /** * Creates a subquery that combines this [[Query]] with another [[Queryable]] by combining elements * in tuples. * * @param right A [[Queryable]] object. * @category Join */ zip(right: Queryable): Query<[T, U]>; /** * Creates a subquery that combines this [[Query]] with another [[Queryable]] by combining elements * using the supplied callback. * * @param right A [[Queryable]] object. * @param selector A callback used to combine two elements. * @category Join */ zip(right: Queryable, selector: (left: T, right: U) => R): Query; /** * Creates an ordered subquery whose elements are sorted in ascending order by the provided key. * * @param keySelector A callback used to select the key for an element. * @param comparer An optional callback used to compare two keys. * @category Order */ orderBy(keySelector: (element: T) => K, comparer?: Comparison | Comparer): OrderedQueryFlow; /** * Creates an ordered subquery whose elements are sorted in descending order by the provided key. * * @param keySelector A callback used to select the key for an element. * @param comparer An optional callback used to compare two keys. * @category Order */ orderByDescending(keySelector: (element: T) => K, comparer?: Comparison | Comparer): OrderedQueryFlow; /** * Creates a [[HierarchyQuery]] using the provided [[HierarchyProvider]]. * * @param hierarchy A [[HierarchyProvider]]. * @category Hierarchy */ toHierarchy(hierarchy: HierarchyProvider): HierarchyQueryFlow; /** * Computes a scalar value by applying an accumulator callback over each element. * * @param accumulator the callback used to compute the result. * @param accumulator.current The current accumulated value. * @param accumulator.element The value to accumulate. * @param accumulator.offset The offset from the start of the underlying [[Queryable]]. * @category Scalar */ reduce(accumulator: (current: T, element: T, offset: number) => T): T; /** * Computes a scalar value by applying an accumulator callback over each element. * * @param accumulator the callback used to compute the result. * @param accumulator.current The current accumulated value. * @param accumulator.element The value to accumulate. * @param accumulator.offset The offset from the start of the underlying [[Queryable]]. * @param seed An optional seed value. * @category Scalar */ reduce(accumulator: (current: U, element: T, offset: number) => U, seed: U, resultSelector?: (result: U, count: number) => U): U; /** * Computes a scalar value by applying an accumulator callback over each element. * * @param accumulator the callback used to compute the result. * @param accumulator.current The current accumulated value. * @param accumulator.element The value to accumulate. * @param accumulator.offset The offset from the start of the underlying [[Queryable]]. * @param seed An optional seed value. * @param resultSelector An optional callback used to compute the final result. * @category Scalar */ reduce(accumulator: (current: U, element: T, offset: number) => U, seed: U, resultSelector: (result: U, count: number) => R): R; /** * Computes a scalar value by applying an accumulator callback over each element in reverse. * * @param accumulator the callback used to compute the result. * @category Scalar */ reduceRight(accumulator: (current: T, element: T, offset: number) => T): T; /** * Computes a scalar value by applying an accumulator callback over each element in reverse. * * @param accumulator the callback used to compute the result. * @param seed An optional seed value. * @category Scalar */ reduceRight(accumulator: (current: U, element: T, offset: number) => U, seed: U, resultSelector?: (result: U, count: number) => U): U; /** * Computes a scalar value by applying an accumulator callback over each element in reverse. * * @param accumulator the callback used to compute the result. * @param seed An optional seed value. * @param resultSelector An optional callback used to compute the final result. * @category Scalar */ reduceRight(accumulator: (current: U, element: T, offset: number) => U, seed: U, resultSelector: (result: U, count: number) => R): R; /** * Counts the number of elements in the [[Query]], optionally filtering elements using the supplied * callback. * * @param predicate An optional callback used to match each element. * @category Scalar */ count(predicate?: (element: T) => boolean): number; /** * Gets the first element in the [[Query]], optionally filtering elements using the supplied * callback. * * @param predicate An optional callback used to match each element. * @category Scalar */ first(predicate: (element: T) => element is U): U | undefined; /** * Gets the first element in the [[Query]], optionally filtering elements using the supplied * callback. * * @param predicate An optional callback used to match each element. * @category Scalar */ first(predicate?: (element: T) => boolean): T | undefined; /** * Gets the last element in the [[Query]], optionally filtering elements using the supplied * callback. * * @param predicate An optional callback used to match each element. * @category Scalar */ last(predicate: (element: T) => element is U): U | undefined; /** * Gets the last element in the [[Query]], optionally filtering elements using the supplied * callback. * * @param predicate An optional callback used to match each element. * @category Scalar */ last(predicate?: (element: T) => boolean): T | undefined; /** * Gets the only element in the [[Query]], or returns `undefined`. * * @param predicate An optional callback used to match each element. * @category Scalar */ single(predicate: (element: T) => element is U): U | undefined; /** * Gets the only element in the [[Query]], or returns undefined. * * @param predicate An optional callback used to match each element. * @category Scalar */ single(predicate?: (element: T) => boolean): T | undefined; /** * Gets the minimum element in the [[Query]], optionally comparing elements using the supplied * callback. * * @param comparer An optional callback used to compare two elements. * @category Scalar */ min(comparer?: Comparison | Comparer): T | undefined; /** * Gets the minimum element by its key in the [[Query]], optionally comparing the keys of each element using the supplied callback. * * @param keySelector A callback used to choose the key to compare. * @param keyComparer An optional callback used to compare the keys. * @category Scalar */ minBy(keySelector: (element: T) => K, keyComparer?: Comparison | Comparer): T | undefined; /** * Gets the maximum element in the [[Query]], optionally comparing elements using the supplied * callback. * * @param comparer An optional callback used to compare two elements. * @category Scalar */ max(comparer?: Comparison | Comparer): T | undefined; /** * Gets the maximum element by its key in the [[Query]], optionally comparing the keys of each element using the supplied callback. * * @param keySelector A callback used to choose the key to compare. * @param keyComparer An optional callback used to compare the keys. * @category Scalar */ maxBy(keySelector: (element: T) => K, keyComparer?: Comparison | Comparer): T | undefined; /** * Computes the sum for a series of numbers. * * @category Scalar */ sum(): T extends number ? number : never; /** * Computes the sum for a series of numbers. * * @category Scalar */ sum(elementSelector: (element: T) => number): number; /** * Computes the average for a series of numbers. * * @category Scalar */ average(): T extends number ? number : never; /** * Computes the average for a series of numbers. * * @category Scalar */ average(elementSelector: (element: T) => number): number; /** * Computes a scalar value indicating whether the [[Query]] contains any elements, * optionally filtering the elements using the supplied callback. * * @param predicate An optional callback used to match each element. * @category Scalar */ some(predicate?: (element: T) => boolean): boolean; /** * Computes a scalar value indicating whether all elements of the [[Query]] * match the supplied callback. * * @param predicate A callback used to match each element. * @category Scalar */ every(predicate: (element: T) => element is U): this is QueryFlow; /** * Computes a scalar value indicating whether all elements of the [[Query]] * match the supplied callback. * * @param predicate A callback used to match each element. * @category Scalar */ every(predicate: (element: T) => boolean): boolean; /** * Computes a scalar value indicating whether every element in this [[Query]] corresponds to a matching element * in another [[Queryable]] at the same position. * * @param right A [[Queryable]] object. * @param equaler An optional callback used to compare the equality of two elements. * @category Scalar */ corresponds(right: Queryable, equaler?: EqualityComparison | Equaler): boolean; /** * Computes a scalar value indicating whether every element in this [[Query]] corresponds to a matching element * in another [[Queryable]] at the same position. * * @param right A [[Queryable]] object. * @param equaler An optional callback used to compare the equality of two elements. * @category Scalar */ corresponds(right: Queryable, equaler: (left: T, right: U) => boolean): boolean; /** * Computes a scalar value indicating whether every element in this [[Query]] corresponds to a matching element * in another [[Queryable]] at the same position. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @category Scalar */ correspondsBy(right: Queryable, keySelector: (element: T) => K): boolean; /** * 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. * * @param right A [[Queryable]] object. * @param leftKeySelector A callback used to select the key for each element in this [[Query]]. * @param rightKeySelector A callback used to select the key for each element in `right`. * @param keyEqualer An optional callback used to compare the equality of two keys. * @category Scalar */ correspondsBy(right: Queryable, leftKeySelector: (element: T) => K, rightKeySelector: (element: U) => K, keyEqualer?: EqualityComparison | Equaler): boolean; /** * Computes a scalar value indicating whether the provided value is included in the [[Query]]. * * @param value A value. * @param equaler An optional callback used to compare the equality of two elements. * @category Scalar */ includes(value: T, equaler?: EqualityComparison | Equaler): boolean; /** * Computes a scalar value indicating whether the provided value is included in the [[Query]]. * * @param value A value. * @param equaler An optional callback used to compare the equality of two elements. * @category Scalar */ includes(value: U, equaler: (left: T, right: U) => boolean): boolean; /** * Computes a scalar value indicating whether the elements of this [[Query]] include * an exact sequence of elements from another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler A callback used to compare the equality of two elements. * @category Scalar */ includesSequence(right: Queryable, equaler?: EqualityComparison | Equaler): boolean; /** * Computes a scalar value indicating whether the elements of this [[Query]] include * an exact sequence of elements from another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler A callback used to compare the equality of two elements. * @category Scalar */ includesSequence(right: Queryable, equaler: (left: T, right: U) => boolean): boolean; /** * Computes a scalar value indicating whether the elements of this [[Query]] start * with the same sequence of elements in another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler A callback used to compare the equality of two elements. * @category Scalar */ startsWith(right: Queryable, equaler?: EqualityComparison | Equaler): boolean; /** * Computes a scalar value indicating whether the elements of this [[Query]] start * with the same sequence of elements in another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler A callback used to compare the equality of two elements. * @category Scalar */ startsWith(right: Queryable, equaler: (left: T, right: U) => boolean): boolean; /** * Computes a scalar value indicating whether the elements of this [[Query]] end * with the same sequence of elements in another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler A callback used to compare the equality of two elements. * @category Scalar */ endsWith(right: Queryable, equaler?: EqualityComparison | Equaler): boolean; /** * Computes a scalar value indicating whether the elements of this [[Query]] end * with the same sequence of elements in another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler A callback used to compare the equality of two elements. * @category Scalar */ endsWith(right: Queryable, equaler: (left: T, right: U) => boolean): boolean; /** * Finds the value in the [[Query]] at the provided offset. A negative offset starts from the * last element. * * @param offset An offset. * @category Scalar */ elementAt(offset: number): T | undefined; /** * Finds the value in the [[Query]] at the provided offset. A negative offset starts from the * last element. * * This is an alias for `elementAt`. * * @param offset An offset. * @category Scalar */ nth(offset: number): T | undefined; /** * 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. * * @param predicate The predicate used to match elements. * @category Scalar */ span(predicate: (element: T, offset: number) => element is U): [Query, Query]; /** * 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. * * @param predicate The predicate used to match elements. * @category Scalar */ span(predicate: (element: T, offset: number) => boolean): [Query, Query]; /** * 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. * * @param predicate The predicate used to match elements. * @category Scalar */ break(predicate: (element: T, offset: number) => boolean): [Query, Query]; /** * Invokes a callback for each element of the [[Query]]. * * @param callback The callback to invoke. * @category Scalar */ forEach(callback: (element: T, offset: number) => void): void; /** * Iterates over all of the elements in the [[Query]], ignoring the results. * @category Scalar */ drain(): void; /** * Eagerly evaluate the [[Query]], returning a new [[Query]]. * @category Scalar */ eval(): QueryFlow; /** * Unzips a sequence of tuples into a tuple of sequences. * @param source A [[Queryable]] * @category Scalar */ unzip(): T extends [any, ...any[]] ? { [I in keyof T]: T[I][]; } : unknown[]; /** * Unzips a sequence of tuples into a tuple of sequences. * @param source A [[Queryable]] * @param partSelector A callback that converts a result into a tuple. * @category Scalar */ unzip(partSelector: (value: T) => U): { [I in keyof U]: U[I][]; }; /** * Creates an Array for the elements of the [[Query]]. * @category Scalar */ toArray(): T[]; /** * Creates an Array for the elements of the [[Query]]. * * @param elementSelector A callback that selects a value for each element. * @category Scalar */ toArray(elementSelector: (element: T) => V): V[]; /** * Creates a `Set` for the elements of the [[Query]]. * @category Scalar */ toSet(): Set; /** * Creates a `Set` for the elements of the [[Query]]. * @param equaler An [[Equaler]] object used to compare equality. * @category Scalar */ toSet(equaler: Equaler): HashSet; /** * Creates a `Set` for the elements of the [[Query]]. * * @param elementSelector A callback that selects a value for each element. * @category Scalar */ toSet(elementSelector: (element: T) => V): Set; /** * Creates a `Set` for the elements of the [[Query]]. * * @param elementSelector A callback that selects a value for each element. * @param equaler An [[Equaler]] object used to compare equality. * @category Scalar */ toSet(elementSelector: (element: T) => V, equaler: Equaler): HashSet; /** * Creates a `Map` for the elements of the [[Query]]. * * @param keySelector A callback used to select a key for each element. * @category Scalar */ toMap(keySelector: (element: T) => K): Map; /** * Creates a `Map` for the elements of the [[Query]]. * * @param keySelector A callback used to select a key for each element. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Scalar */ toMap(keySelector: (element: T) => K, keyEqualer: Equaler): HashMap; /** * Creates a `Map` for the elements of the [[Query]]. * * @param keySelector A callback used to select a key for each element. * @param elementSelector A callback that selects a value for each element. * @category Scalar */ toMap(keySelector: (element: T) => K, elementSelector: (element: T) => V): Map; /** * Creates a `Map` for the elements of the [[Query]]. * * @param keySelector A callback used to select a key for each element. * @param elementSelector A callback that selects a value for each element. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Scalar */ toMap(keySelector: (element: T) => K, elementSelector: (element: T) => V, keyEqualer: Equaler): HashMap; /** * Creates a `Lookup` for the elements of the [[Query]]. * * @param keySelector A callback used to select a key for each element. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Scalar */ toLookup(keySelector: (element: T) => K, keyEqualer?: Equaler): Lookup; /** * Creates a `Lookup` for the elements of the [[Query]]. * * @param keySelector A callback used to select a key for each element. * @param elementSelector A callback that selects a value for each element. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Scalar */ toLookup(keySelector: (element: T) => K, elementSelector: (element: T) => V, keyEqualer?: Equaler): Lookup; /** * Creates an Object for the elements of the [[Query]]. Properties are added via `Object.defineProperty`. * * ```ts * // As a regular object * const obj = from([["x", 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([["x", 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([["x", 1], ["y", 2]]).toObject(null, a => a[0]); * obj.x; // ["x", 1] * obj.y; // ["y", 2] * typeof obj.toString; // undefined * ``` * * @param prototype 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. * @param keySelector A callback used to select a key for each element. * @category Scalar */ toObject(prototype: object | null | undefined, keySelector: (element: T) => PropertyKey): object; /** * Creates an Object for the elements the [[Query]]. Properties are added via `Object.defineProperty`. * * ```ts * // As a regular object * const obj = from([["x", 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([["x", 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([["x", 1], ["y", 2]]).toObject(null, a => a[0], a => a[1]); * obj.x; // 1 * obj.y; // 2 * typeof obj.toString; // undefined * ``` * * @param prototype 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. * @param keySelector A callback used to select a key for each element. * @param elementSelector A callback that selects a value for each element. * @param descriptorSelector A callback that defines the `PropertyDescriptor` for each property. * @category Scalar */ toObject(prototype: object | null | undefined, keySelector: (element: T) => PropertyKey, elementSelector: (element: T) => V, descriptorSelector?: (key: PropertyKey, element: V) => PropertyDescriptor): object; /** * Writes each element to a destination array. * * @param dest The destination array. * @param start The offset into the array at which to start writing. * @param count The number of elements to write to the array. * @category Scalar */ copyTo>(dest: U, start?: number, count?: number): U; toJSON(): T[]; [Symbol.iterator](): Iterator; } /** * Represents a sequence of hierarchically organized values. */ export declare class HierarchyQuery extends Query implements HierarchyIterable { constructor(source: HierarchyIterable); constructor(source: Queryable, hierarchy: HierarchyProvider); /** * Creates a subquery for the roots of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ root(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for the roots of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ root(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for the ancestors of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ ancestors(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for the ancestors of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ ancestors(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for the ancestors of each element as well as each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ ancestorsAndSelf(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for the ancestors of each element as well as each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ ancestorsAndSelf(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for the descendants of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ descendants(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for the descendants of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ descendants(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for the descendants of each element as well as each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ descendantsAndSelf(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for the descendants of each element as well as each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ descendantsAndSelf(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for this [[query]]. * * @param predicate A callback used to filter the results. * @category Hierarchy */ self(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for this [[query]]. * * @param predicate A callback used to filter the results. * @category Hierarchy */ self(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for this [[query]]. * * @param predicate A callback used to filter the results. * @category Hierarchy */ self(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for the parents of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ parents(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for the parents of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ parents(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for the children of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ children(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for the children of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ children(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for the siblings of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ siblings(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for the siblings of each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ siblings(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for the siblings of each element as well as each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ siblingsAndSelf(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for the siblings of each element as well as each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ siblingsAndSelf(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for the siblings before each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ siblingsBeforeSelf(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for the siblings before each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ siblingsBeforeSelf(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for the siblings after each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ siblingsAfterSelf(predicate: (element: TNode) => element is U): HierarchyQuery; /** * Creates a subquery for the siblings after each element in the hierarchy. * * @param predicate A callback used to filter the results. * @category Hierarchy */ siblingsAfterSelf(predicate?: (element: TNode) => boolean): HierarchyQuery; /** * Creates a subquery for the child of each element at the specified offset. A negative offset * starts from the last child. * * @param offset The offset for the child. * @category Hierarchy */ nthChild(offset: number): HierarchyQuery; /** * Creates a subquery for the top-most elements. Elements that are a descendant of any other * element are removed. * @category Hierarchy */ topMost(predicate: (element: T) => element is U): HierarchyQuery; /** * Creates a subquery for the top-most elements. Elements that are a descendant of any other * element are removed. * @category Hierarchy */ topMost(predicate?: (element: T) => boolean): HierarchyQuery; /** * Creates a subquery for the bottom-most elements. Elements that are an ancestor of any other * element are removed. * @category Hierarchy */ bottomMost(predicate: (element: T) => element is U): HierarchyQuery; /** * Creates a subquery for the bottom-most elements. Elements that are an ancestor of any other * element are removed. * @category Hierarchy */ bottomMost(predicate?: (element: T) => boolean): HierarchyQuery; [Hierarchical.hierarchy](): HierarchyProvider; } export interface HierarchyQuery { /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler An [[Equaler]] object used to compare equality. * @category Subquery */ intersect(right: HierarchyIterable, equaler?: Equaler): HierarchyQuery; /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler An [[Equaler]] object used to compare equality. * @category Subquery */ intersect(right: Queryable, equaler?: Equaler): HierarchyQuery; /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]]. * * @param right A [[Queryable]] object. * @param equaler An [[Equaler]] object used to compare equality. * @category Subquery */ intersect(right: Queryable, equaler?: Equaler): HierarchyQuery; /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]], where set identity is determined by the selected key. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ intersectBy(right: HierarchyIterable, keySelector: (element: T) => K, keyEqualer?: Equaler): HierarchyQuery; /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]], where set identity is determined by the selected key. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ intersectBy(right: Queryable, keySelector: (element: T) => K, keyEqualer?: Equaler): HierarchyQuery; /** * Creates a subquery for the set intersection of this [[Query]] and another [[Queryable]], where set identity is determined by the selected key. * * @param right A [[Queryable]] object. * @param keySelector A callback used to select the key for each element. * @param keySelector.element An element from which to select a key. * @param keyEqualer An [[Equaler]] object used to compare key equality. * @category Subquery */ intersectBy(right: Queryable, keySelector: (element: T) => K, keyEqualer?: Equaler): HierarchyQuery; } /** * Represents an ordered sequence of elements. */ export declare class OrderedQuery extends Query implements OrderedIterable { constructor(source: OrderedIterable); /** * Creates a subsequent ordered subquery whose elements are sorted in ascending order by the provided key. * * @param keySelector A callback used to select the key for an element. * @param comparer An optional callback used to compare two keys. * @category Order */ thenBy(keySelector: (element: T) => K, comparer?: Comparison | Comparer): OrderedQuery; /** * Creates a subsequent ordered subquery whose elements are sorted in descending order by the provided key. * * @param keySelector A callback used to select the key for an element. * @param comparer An optional callback used to compare two keys. * @category Order */ thenByDescending(keySelector: (element: T) => K, comparer?: Comparison | Comparer): OrderedQuery; [OrderedIterable.thenBy](keySelector: (element: T) => K, comparer: Comparison | Comparer, descending: boolean): OrderedIterable; } /** * Represents an ordered sequence of hierarchically organized values. */ export declare class OrderedHierarchyQuery extends HierarchyQuery implements OrderedHierarchyIterable { constructor(source: OrderedHierarchyIterable); constructor(source: OrderedIterable, hierarchy: HierarchyProvider); /** * Creates a subsequent ordered subquery whose elements are sorted in ascending order by the provided key. * * @param keySelector A callback used to select the key for an element. * @param comparison An optional callback used to compare two keys. * @category Order */ thenBy(keySelector: (element: T) => K, comparison?: Comparison | Comparer): OrderedHierarchyQuery; /** * Creates a subsequent ordered subquery whose elements are sorted in descending order by the provided key. * * @param keySelector A callback used to select the key for an element. * @param comparison An optional callback used to compare two keys. * @category Order */ thenByDescending(keySelector: (element: T) => K, comparison?: Comparison | Comparer): OrderedHierarchyQuery; [OrderedIterable.thenBy](keySelector: (element: T) => K, comparison: Comparison | Comparer, descending: boolean): OrderedHierarchyIterable; } //# sourceMappingURL=query.d.ts.map