tyneq / TyneqSequence
Interface: TyneqSequence<TSource>
Defined in: src/types/core.ts:101
The primary public API for a lazy sequence - the type returned by all Tyneq operators.
Remarks
Every operator method returns a new TyneqSequence without consuming the source. The source is not iterated until the returned sequence is iterated.
Extends
Enumerable<TSource>
Extended by
Type Parameters
| Type Parameter | Description |
|---|---|
TSource | Element type. |
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
[tyneqQueryNode] | readonly | Nullable<IQueryNode> | The query plan node for this sequence, or null if no plan is available. Remarks Use QueryPlanPrinter to render this as a string. Sequences created via pipe() always have null here. | src/types/core.ts:113 |
Methods
getEnumerator()
getEnumerator():
Enumerator<TSource>
Defined in: src/types/core.ts:39
Returns a new, independent enumerator starting at the beginning of the sequence.
Returns
Enumerator<TSource>
Inherited from
[iterator]()
[iterator]():
Enumerator<TSource>
Defined in: src/types/core.ts:73
Returns
Enumerator<TSource>
Inherited from
any()
any(
predicate):boolean
Defined in: src/types/core.ts:130
Returns true if any element satisfies the predicate.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
Returns
boolean
Remarks
Returns false for an empty sequence. The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
all()
all(
predicate):boolean
Defined in: src/types/core.ts:142
Returns true if all elements satisfy the predicate.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
Returns
boolean
Remarks
Returns true for an empty sequence (vacuous truth). The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
contains()
contains(
value,equalityComparer?):boolean
Defined in: src/types/core.ts:154
Returns true if the source sequence contains value.
Parameters
| Parameter | Type |
|---|---|
value | TSource |
equalityComparer? | EqualityComparer<TSource> |
Returns
boolean
Remarks
Uses equalityComparer for element comparison, or === when omitted. Returns false for an empty sequence. Enumerates the source until a match is found or the sequence is exhausted.
Throws
When equalityComparer is null (undefined is allowed).
count()
count():
number
Defined in: src/types/core.ts:162
Returns the number of elements.
Returns
number
Remarks
Returns 0 for an empty sequence.
countBy()
countBy(
predicate):number
Defined in: src/types/core.ts:174
Returns the number of elements that satisfy the predicate.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
Returns
number
Remarks
Returns 0 if no elements match or the sequence is empty. The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
consume()
consume():
void
Defined in: src/types/core.ts:182
Iterates the entire sequence and discards all elements.
Returns
void
Remarks
Useful for triggering side effects (e.g., after tap).
isNullOrEmpty()
isNullOrEmpty():
boolean
Defined in: src/types/core.ts:187
Returns true if the sequence is empty or if the first element is null or undefined.
Returns
boolean
elementAt()
elementAt(
index):TSource
Defined in: src/types/core.ts:195
Returns the element at index.
Parameters
| Parameter | Type |
|---|---|
index | number |
Returns
TSource
Throws
When index is not a safe integer.
Throws
When index is negative or greater than or equal to the sequence length.
elementAtOrDefault()
elementAtOrDefault(
index,defaultValue):TSource
Defined in: src/types/core.ts:203
Returns the element at index, or defaultValue if the index is out of range.
Parameters
| Parameter | Type |
|---|---|
index | number |
defaultValue | TSource |
Returns
TSource
Throws
When index is not a safe integer.
Throws
When index is negative.
first()
first(
predicate):TSource
Defined in: src/types/core.ts:215
Returns the first element that satisfies the predicate.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
Returns
TSource
Remarks
The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
Throws
When no element satisfies the predicate.
firstOrDefault()
firstOrDefault(
predicate,defaultValue):TSource
Defined in: src/types/core.ts:226
Returns the first element that satisfies the predicate, or defaultValue if none does.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
defaultValue | TSource |
Returns
TSource
Remarks
The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
indexOf()
indexOf(
predicate,startIndex?):number
Defined in: src/types/core.ts:240
Returns the zero-based index of the first element that satisfies the predicate.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
startIndex? | number |
Returns
number
Remarks
Returns -1 if no element satisfies the predicate. When startIndex is provided, the search starts at that index. The predicate receives each element and its zero-based index within the full sequence.
Throws
When predicate is null.
Throws
When predicate is undefined.
Throws
When startIndex is negative.
last()
last(
predicate):TSource
Defined in: src/types/core.ts:252
Returns the last element that satisfies the predicate.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
Returns
TSource
Remarks
The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
Throws
When no element satisfies the predicate.
lastOrDefault()
lastOrDefault(
predicate,defaultValue):TSource
Defined in: src/types/core.ts:263
Returns the last element that satisfies the predicate, or defaultValue if none does.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
defaultValue | TSource |
Returns
TSource
Remarks
The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
max()
max(
comparer?):TSource
Defined in: src/types/core.ts:273
Returns the maximum element according to the comparer.
Parameters
| Parameter | Type |
|---|---|
comparer? | Comparer<TSource> |
Returns
TSource
Remarks
Uses the natural > operator when no comparer is provided.
Throws
When the sequence is empty.
maxBy()
maxBy<
TKey>(keySelector,comparer?):TSource
Defined in: src/types/core.ts:282
Returns the element with the maximum key.
Type Parameters
| Type Parameter |
|---|
TKey |
Parameters
| Parameter | Type |
|---|---|
keySelector | (element) => TKey |
comparer? | Comparer<TKey> |
Returns
TSource
Throws
When the sequence is empty.
Throws
When keySelector is null.
Throws
When keySelector is undefined.
min()
min(
comparer?):TSource
Defined in: src/types/core.ts:292
Returns the minimum element according to the comparer.
Parameters
| Parameter | Type |
|---|---|
comparer? | Comparer<TSource> |
Returns
TSource
Remarks
Uses the natural < operator when no comparer is provided.
Throws
When the sequence is empty.
minBy()
minBy<
TKey>(keySelector,comparer?):TSource
Defined in: src/types/core.ts:301
Returns the element with the minimum key.
Type Parameters
| Type Parameter |
|---|
TKey |
Parameters
| Parameter | Type |
|---|---|
keySelector | (element) => TKey |
comparer? | Comparer<TKey> |
Returns
TSource
Throws
When the sequence is empty.
Throws
When keySelector is null.
Throws
When keySelector is undefined.
sequenceEqual()
sequenceEqual(
other,equalityComparer?):boolean
Defined in: src/types/core.ts:310
Returns true if this sequence and other have the same elements in the same order.
Parameters
| Parameter | Type |
|---|---|
other | Iterable<TSource> |
equalityComparer? | EqualityComparer<TSource> |
Returns
boolean
Remarks
Uses equalityComparer for element comparison, or === when omitted. Returns true if both sequences are empty.
single()
single(
predicate):TSource
Defined in: src/types/core.ts:322
Returns the only element that satisfies the predicate.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
Returns
TSource
Remarks
The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
Throws
When no element satisfies the predicate, or when more than one does.
singleOrDefault()
singleOrDefault(
predicate,defaultValue):TSource
Defined in: src/types/core.ts:334
Returns the only element that satisfies the predicate, or defaultValue if none does.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
defaultValue | TSource |
Returns
TSource
Remarks
The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
Throws
When more than one element satisfies the predicate.
endsWith()
endsWith(
sequence,equalityComparer?):boolean
Defined in: src/types/core.ts:363
Returns true if this sequence ends with all elements of sequence in order.
Parameters
| Parameter | Type |
|---|---|
sequence | Iterable<TSource> |
equalityComparer? | EqualityComparer<TSource> |
Returns
boolean
Remarks
Uses equalityComparer for element comparison, or === when omitted. Returns true when sequence is empty (vacuous truth). Returns false when sequence is longer than the source.
Example
Tyneq.from([1, 2, 3, 4, 5]).endsWith([4, 5]); // true
Tyneq.from([1, 2, 3, 4, 5]).endsWith([3, 5]); // false
Tyneq.from([1, 2, 3]).endsWith([]); // true
Tyneq.from([1, 2]).endsWith([1, 2, 3]); // false
// Custom equality
Tyneq.from(["A", "B", "C"]).endsWith(
["b", "c"],
(a, b) => a.toLowerCase() === b.toLowerCase()
); // trueThrows
When sequence is null.
Throws
When sequence is undefined.
Throws
When sequence is not iterable.
Throws
When equalityComparer is null (undefined is allowed).
startsWith()
startsWith(
sequence,equalityComparer?):boolean
Defined in: src/types/core.ts:378
Returns true if this sequence starts with all elements of sequence in order.
Parameters
| Parameter | Type |
|---|---|
sequence | Iterable<TSource> |
equalityComparer? | EqualityComparer<TSource> |
Returns
boolean
Remarks
Uses equalityComparer for element comparison, or === when omitted. Returns true when sequence is empty (vacuous truth). Returns false when sequence is longer than the source.
Throws
When sequence is null.
Throws
When sequence is undefined.
Throws
When sequence is not iterable.
Throws
When equalityComparer is null (undefined is allowed).
sum()
sum(
selector):number
Defined in: src/types/core.ts:389
Returns the sum of selector applied to each element.
Parameters
| Parameter | Type |
|---|---|
selector | (item) => number |
Returns
number
Remarks
Returns 0 for an empty sequence.
Throws
When selector is null.
Throws
When selector is undefined.
toArray()
toArray():
TSource[]
Defined in: src/types/core.ts:397
Materializes the sequence into an array.
Returns
TSource[]
Remarks
Returns [] for an empty sequence.
toAsync()
toAsync():
AsyncIterable<TSource>
Defined in: src/types/core.ts:405
Returns an AsyncIterable that iterates this sequence asynchronously.
Returns
AsyncIterable<TSource>
Remarks
Deferred - each for await...of loop produces a fresh traversal of the source.
toMap()
toMap<
TKey,TValue>(selector):Map<TKey,TValue>
Defined in: src/types/core.ts:413
Materializes the sequence into a Map.
Type Parameters
| Type Parameter |
|---|
TKey |
TValue |
Parameters
| Parameter | Type |
|---|---|
selector | (item) => KeyValuePair<TKey, TValue> |
Returns
Map<TKey, TValue>
Throws
When selector is null.
Throws
When selector is undefined.
toRecord()
toRecord<
TKey,TValue>(selector):Record<TKey,TValue>
Defined in: src/types/core.ts:421
Materializes the sequence into a plain object record.
Type Parameters
| Type Parameter |
|---|
TKey extends string | number | symbol |
TValue |
Parameters
| Parameter | Type |
|---|---|
selector | (item) => KeyValuePair<TKey, TValue> |
Returns
Record<TKey, TValue>
Throws
When selector is null.
Throws
When selector is undefined.
toSet()
toSet():
Set<TSource>
Defined in: src/types/core.ts:429
Materializes the sequence into a Set.
Returns
Set<TSource>
Remarks
Duplicate elements are deduplicated using Set identity semantics.
average()
average(
selector):number
Defined in: src/types/core.ts:438
Returns the arithmetic mean of selector applied to each element.
Parameters
| Parameter | Type |
|---|---|
selector | (item) => number |
Returns
number
Throws
When the sequence is empty.
Throws
When selector is null.
Throws
When selector is undefined.
aggregate()
aggregate<
UAccumulate,VResult>(seed,func,resultSelector):VResult
Defined in: src/types/core.ts:449
Folds the sequence into a single result value.
Type Parameters
| Type Parameter |
|---|
UAccumulate |
VResult |
Parameters
| Parameter | Type |
|---|---|
seed | UAccumulate |
func | (accumulate, item) => UAccumulate |
resultSelector | (accumulate) => VResult |
Returns
VResult
Remarks
Applies func to each element in order, starting from seed. Returns resultSelector(seed) for an empty sequence.
Throws
When func or resultSelector is null.
Throws
When func or resultSelector is undefined.
append()
append(
item):TyneqSequence<TSource>
Defined in: src/types/core.ts:462
Returns a new sequence with item appended after all source elements.
Parameters
| Parameter | Type |
|---|---|
item | TSource |
Returns
TyneqSequence<TSource>
chunk()
chunk(
size):TyneqSequence<TSource[]>
Defined in: src/types/core.ts:473
Partitions the sequence into non-overlapping arrays of length size.
Parameters
| Parameter | Type |
|---|---|
size | number |
Returns
TyneqSequence<TSource[]>
Remarks
The last chunk may be shorter than size if the sequence length is not divisible by size.
Throws
When size is not a safe integer.
Throws
When size is less than or equal to 0.
concat()
concat(
other):TyneqSequence<TSource>
Defined in: src/types/core.ts:476
Returns a new sequence with the elements of other appended after the source.
Parameters
| Parameter | Type |
|---|---|
other | Iterable<TSource> |
Returns
TyneqSequence<TSource>
defaultIfEmpty()
defaultIfEmpty(
defaultValue):TyneqSequence<TSource>
Defined in: src/types/core.ts:484
Returns a sequence that yields defaultValue when the source is empty.
Parameters
| Parameter | Type |
|---|---|
defaultValue | TSource |
Returns
TyneqSequence<TSource>
Remarks
Passes source elements through unchanged when the source is non-empty.
flatten()
flatten<
TInner>(this):TyneqSequence<TInner>
Defined in: src/types/core.ts:503
Flattens one level of nesting from a sequence of iterables.
Type Parameters
| Type Parameter |
|---|
TInner |
Parameters
| Parameter | Type |
|---|---|
this | TyneqSequence<Iterable<TInner, any, any>> |
Returns
TyneqSequence<TInner>
Remarks
Deferred. Each inner iterable is consumed lazily as the outer sequence advances. Returns an empty sequence when the source is empty. Equivalent to selectMany(x => x) but without requiring a selector.
Example
Tyneq.from([[1, 2], [3, 4], [5]]).flatten().toArray();
// [1, 2, 3, 4, 5]
Tyneq.from(["hello", "world"]).flatten().toArray();
// ["h", "e", "l", "l", "o", "w", "o", "r", "l", "d"]pairwise()
pairwise():
TyneqSequence<[TSource,TSource]>
Defined in: src/types/core.ts:511
Returns consecutive overlapping pairs of elements: [e0,e1], [e1,e2], ...
Returns
TyneqSequence<[TSource, TSource]>
Remarks
Returns an empty sequence when the source has fewer than two elements.
ofType()
ofType<
U>(guard):TyneqSequence<U>
Defined in: src/types/core.ts:519
Filters elements to those for which guard returns true, narrowing the type to U.
Type Parameters
| Type Parameter |
|---|
U |
Parameters
| Parameter | Type |
|---|---|
guard | (value) => value is U |
Returns
TyneqSequence<U>
Throws
When guard is null.
Throws
When guard is undefined.
prepend()
prepend(
item):TyneqSequence<TSource>
Defined in: src/types/core.ts:522
Returns a new sequence with item prepended before all source elements.
Parameters
| Parameter | Type |
|---|---|
item | TSource |
Returns
TyneqSequence<TSource>
repeat()
repeat(
count):TyneqSequence<TSource>
Defined in: src/types/core.ts:543
Repeats the source sequence count times.
Parameters
| Parameter | Type |
|---|---|
count | number |
Returns
TyneqSequence<TSource>
Remarks
Deferred. Re-enumerates the source from the beginning for each repetition. Returns an empty sequence when count is 0.
Example
Tyneq.from([1, 2]).repeat(3).toArray();
// [1, 2, 1, 2, 1, 2]
Tyneq.from([1, 2]).repeat(0).toArray();
// []Throws
When count is negative.
Throws
When count is not an integer.
populate()
populate<
TValue>(value):TyneqSequence<TValue>
Defined in: src/types/core.ts:551
Replaces each element with value, keeping the same sequence length.
Type Parameters
| Type Parameter |
|---|
TValue |
Parameters
| Parameter | Type |
|---|---|
value | TValue |
Returns
TyneqSequence<TValue>
Remarks
Useful for generating a sequence of a fixed value with a known length derived from the source.
select()
select<
TResult>(selector):TyneqSequence<TResult>
Defined in: src/types/core.ts:562
Projects each element through selector.
Type Parameters
| Type Parameter |
|---|
TResult |
Parameters
| Parameter | Type |
|---|---|
selector | ItemSelector<TSource, TResult> |
Returns
TyneqSequence<TResult>
Remarks
The selector receives each element and its zero-based index.
Throws
When selector is null.
Throws
When selector is undefined.
selectMany()
selectMany<
TResult>(selector):TyneqSequence<TResult>
Defined in: src/types/core.ts:570
Projects each element to an iterable and flattens the results into a single sequence.
Type Parameters
| Type Parameter |
|---|
TResult |
Parameters
| Parameter | Type |
|---|---|
selector | (item) => Iterable<TResult> |
Returns
TyneqSequence<TResult>
Throws
When selector is null.
Throws
When selector is undefined.
window()
window(
size,step?):TyneqSequence<TSource[]>
Defined in: src/types/core.ts:598
Yields fixed-size windows (sub-arrays) over the source sequence.
Parameters
| Parameter | Type |
|---|---|
size | number |
step? | number |
Returns
TyneqSequence<TSource[]>
Remarks
Deferred. O(size) memory - only the current window is held in memory. When step is 1 (the default), windows slide one element at a time (overlapping). When step equals size, windows are non-overlapping (tumbling). When step exceeds size, elements between windows are skipped (gaps). Yields no windows when the source has fewer than size elements. Each yielded array is a snapshot - mutating it does not affect subsequent windows.
Example
// Sliding (default step = 1)
Tyneq.range(1, 5).window(3).toArray();
// [[1,2,3], [2,3,4], [3,4,5]]
// Tumbling (step = size)
Tyneq.range(1, 6).window(2, 2).toArray();
// [[1,2], [3,4], [5,6]]Throws
When size or step is not a safe integer.
Throws
When size is less than 1.
Throws
When step is less than 1.
skip()
skip(
count):TyneqSequence<TSource>
Defined in: src/types/core.ts:610
Skips the first count elements.
Parameters
| Parameter | Type |
|---|---|
count | number |
Returns
TyneqSequence<TSource>
Remarks
Returns an empty sequence when count exceeds the sequence length. count must be non-negative.
Throws
When count is not a safe integer.
Throws
When count is negative.
skipLast()
skipLast(
count):TyneqSequence<TSource>
Defined in: src/types/core.ts:621
Skips the last count elements.
Parameters
| Parameter | Type |
|---|---|
count | number |
Returns
TyneqSequence<TSource>
Remarks
Buffers count elements to determine the cutoff.
Throws
When count is not a safe integer.
Throws
When count is negative.
skipUntil()
skipUntil(
predicate):TyneqSequence<TSource>
Defined in: src/types/core.ts:634
Skips elements until predicate returns true, then yields all remaining elements including the one that triggered the predicate.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
Returns
TyneqSequence<TSource>
Remarks
The predicate receives each element and its zero-based index. Once the predicate returns true it is never called again.
Throws
When predicate is null.
Throws
When predicate is undefined.
skipWhile()
skipWhile(
predicate):TyneqSequence<TSource>
Defined in: src/types/core.ts:645
Skips elements while predicate returns true, then yields the rest.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
Returns
TyneqSequence<TSource>
Remarks
The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
slice()
slice(
start,end?):TyneqSequence<TSource>
Defined in: src/types/core.ts:667
Yields elements between start (inclusive) and end (exclusive) by index.
Parameters
| Parameter | Type |
|---|---|
start | number |
end? | number |
Returns
TyneqSequence<TSource>
Remarks
Deferred. Enumerates only as far as end. When end is omitted, yields all elements from start to the end of the sequence. Returns an empty sequence when start is beyond the sequence length.
Example
Tyneq.from([0, 1, 2, 3, 4]).slice(1, 4).toArray();
// [1, 2, 3]
Tyneq.from([0, 1, 2, 3, 4]).slice(2).toArray();
// [2, 3, 4]Throws
When start is negative.
Throws
When end is negative or less than start.
split()
split(
splitOn):TyneqSequence<TSource[]>
Defined in: src/types/core.ts:678
Splits the sequence at elements where splitOn returns true.
Parameters
| Parameter | Type |
|---|---|
splitOn | (item) => boolean |
Returns
TyneqSequence<TSource[]>
Remarks
The delimiter elements are consumed and not included in any sub-array.
Throws
When splitOn is null.
Throws
When splitOn is undefined.
take()
take(
count):TyneqSequence<TSource>
Defined in: src/types/core.ts:686
Takes at most the first count elements.
Parameters
| Parameter | Type |
|---|---|
count | number |
Returns
TyneqSequence<TSource>
Throws
When count is not a safe integer.
Throws
When count is negative.
takeUntil()
takeUntil(
predicate):TyneqSequence<TSource>
Defined in: src/types/core.ts:699
Yields elements until predicate returns true, then stops. The element that triggered the predicate is not included.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
Returns
TyneqSequence<TSource>
Remarks
The predicate receives each element and its zero-based index. Once the predicate returns true the sequence ends immediately.
Throws
When predicate is null.
Throws
When predicate is undefined.
takeWhile()
takeWhile(
predicate):TyneqSequence<TSource>
Defined in: src/types/core.ts:710
Takes elements while predicate returns true, then stops.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
Returns
TyneqSequence<TSource>
Remarks
The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
tap()
tap(
action):TyneqSequence<TSource>
Defined in: src/types/core.ts:721
Executes action for each element as it passes through the pipeline, then yields it unchanged.
Parameters
| Parameter | Type |
|---|---|
action | ItemAction<TSource> |
Returns
TyneqSequence<TSource>
Remarks
The action receives each element and its zero-based index.
Throws
When action is null.
Throws
When action is undefined.
tapIf()
tapIf(
action,predicate):TyneqSequence<TSource>
Defined in: src/types/core.ts:732
Executes action for each element only while predicate() returns true.
Parameters
| Parameter | Type |
|---|---|
action | ItemAction<TSource> |
predicate | () => boolean |
Returns
TyneqSequence<TSource>
Remarks
The action receives each element and its zero-based index.
Throws
When action or predicate is null.
Throws
When action or predicate is undefined.
throttle()
throttle(
count):TyneqSequence<TSource>
Defined in: src/types/core.ts:740
Yields every count-th element (i.e. elements at indices 0, count, 2*count, ...).
Parameters
| Parameter | Type |
|---|---|
count | number |
Returns
TyneqSequence<TSource>
Throws
When count is not a safe integer.
Throws
When count is less than or equal to 0.
where()
where(
predicate):TyneqSequence<TSource>
Defined in: src/types/core.ts:751
Yields only elements for which predicate returns true.
Parameters
| Parameter | Type |
|---|---|
predicate | ItemPredicate<TSource> |
Returns
TyneqSequence<TSource>
Remarks
The predicate receives each element and its zero-based index.
Throws
When predicate is null.
Throws
When predicate is undefined.
zip()
zip<
TOther,TResult>(other,selector):TyneqSequence<TResult>
Defined in: src/types/core.ts:763
Pairs each element with the corresponding element from other using selector.
Type Parameters
| Type Parameter |
|---|
TOther |
TResult |
Parameters
| Parameter | Type |
|---|---|
other | Iterable<TOther> |
selector | (first, second) => TResult |
Returns
TyneqSequence<TResult>
Remarks
Stops at the shorter of the two sequences.
Throws
When other or selector is null.
Throws
When other or selector is undefined.
Throws
When other is not iterable.
distinct()
distinct():
TyneqSequence<TSource>
Defined in: src/types/core.ts:772
Returns the sequence without duplicate elements, using SameValueZero (Set) equality.
Returns
TyneqSequence<TSource>
distinctBy()
distinctBy<
TKey>(keySelector):TyneqSequence<TSource>
Defined in: src/types/core.ts:780
Returns the sequence without duplicate elements, comparing by the result of keySelector.
Type Parameters
| Type Parameter |
|---|
TKey |
Parameters
| Parameter | Type |
|---|---|
keySelector | (item) => TKey |
Returns
TyneqSequence<TSource>
Throws
When keySelector is null.
Throws
When keySelector is undefined.
except()
except(
excludedValues):TyneqSequence<TSource>
Defined in: src/types/core.ts:783
Returns elements not present in excludedValues, using SameValueZero (Set) equality.
Parameters
| Parameter | Type |
|---|---|
excludedValues | Iterable<TSource> |
Returns
TyneqSequence<TSource>
exceptBy()
exceptBy<
TKey>(excludedKeys,keySelector):TyneqSequence<TSource>
Defined in: src/types/core.ts:791
Returns elements whose key (via keySelector) is not found in excludedKeys.
Type Parameters
| Type Parameter |
|---|
TKey |
Parameters
| Parameter | Type |
|---|---|
excludedKeys | Iterable<TKey> |
keySelector | (item) => TKey |
Returns
TyneqSequence<TSource>
Throws
When keySelector is null.
Throws
When keySelector is undefined.
groupBy()
groupBy<
TKey,TValue,TResult>(keySelector,valueSelector,resultSelector):TyneqSequence<TResult>
Defined in: src/types/core.ts:799
Groups elements by key and projects each group with resultSelector.
Type Parameters
| Type Parameter |
|---|
TKey |
TValue |
TResult |
Parameters
| Parameter | Type |
|---|---|
keySelector | (item) => TKey |
valueSelector | (item) => TValue |
resultSelector | (key, values) => TResult |
Returns
TyneqSequence<TResult>
Throws
When keySelector, valueSelector, or resultSelector is null.
Throws
When keySelector, valueSelector, or resultSelector is undefined.
groupJoin()
groupJoin<
TInner,TKey,TResult>(inner,outerKeySelector,innerKeySelector,resultSelector):TyneqSequence<TResult>
Defined in: src/types/core.ts:815
Performs a left outer join: each outer element is paired with its matching inner group.
Type Parameters
| Type Parameter |
|---|
TInner |
TKey |
TResult |
Parameters
| Parameter | Type |
|---|---|
inner | Iterable<TInner> |
outerKeySelector | (outer) => TKey |
innerKeySelector | (inner) => TKey |
resultSelector | (outer, group) => TResult |
Returns
TyneqSequence<TResult>
Remarks
Elements with no match in inner receive an empty group.
Throws
When any selector is null.
Throws
When any selector is undefined.
Throws
When inner is not iterable.
intersect()
intersect(
intersectedValues):TyneqSequence<TSource>
Defined in: src/types/core.ts:823
Returns elements that are also present in intersectedValues, using SameValueZero (Set) equality.
Parameters
| Parameter | Type |
|---|---|
intersectedValues | Iterable<TSource> |
Returns
TyneqSequence<TSource>
intersectBy()
intersectBy<
TKey>(intersectedKeys,keySelector):TyneqSequence<TSource>
Defined in: src/types/core.ts:831
Returns elements whose key (via keySelector) is found in intersectedKeys.
Type Parameters
| Type Parameter |
|---|
TKey |
Parameters
| Parameter | Type |
|---|---|
intersectedKeys | Iterable<TKey> |
keySelector | (item) => TKey |
Returns
TyneqSequence<TSource>
Throws
When keySelector is null.
Throws
When keySelector is undefined.
join()
join<
TInner,TKey,TResult>(inner,outerKeySelector,innerKeySelector,resultSelector):TyneqSequence<TResult>
Defined in: src/types/core.ts:839
Performs an inner join: produces one result for each matching pair of outer and inner elements.
Type Parameters
| Type Parameter |
|---|
TInner |
TKey |
TResult |
Parameters
| Parameter | Type |
|---|---|
inner | Iterable<TInner> |
outerKeySelector | (outer) => TKey |
innerKeySelector | (inner) => TKey |
resultSelector | (outer, inner) => TResult |
Returns
TyneqSequence<TResult>
Throws
When any selector is null.
Throws
When any selector is undefined.
memoize()
memoize():
TyneqCachedSequence<TSource>
Defined in: src/types/core.ts:853
Returns a sequence that caches elements incrementally as they are iterated.
Returns
TyneqCachedSequence<TSource>
Remarks
Subsequent iterations replay the cache; the source is only iterated once. Call refresh() on the returned sequence to clear the cache and re-enumerate the source.
orderBy()
orderBy<
TKey>(keySelector,comparer?):TyneqOrderedSequence<TSource>
Defined in: src/types/core.ts:864
Returns the sequence sorted in ascending order by keySelector.
Type Parameters
| Type Parameter |
|---|
TKey |
Parameters
| Parameter | Type |
|---|---|
keySelector | (item) => TKey |
comparer? | Comparer<TKey> |
Returns
TyneqOrderedSequence<TSource>
Remarks
Stable sort. Append thenBy/thenByDescending for multi-key sorting.
Throws
When keySelector is null.
Throws
When keySelector is undefined.
orderByDescending()
orderByDescending<
TKey>(keySelector,comparer?):TyneqOrderedSequence<TSource>
Defined in: src/types/core.ts:878
Returns the sequence sorted in descending order by keySelector.
Type Parameters
| Type Parameter |
|---|
TKey |
Parameters
| Parameter | Type |
|---|---|
keySelector | (item) => TKey |
comparer? | Comparer<TKey> |
Returns
TyneqOrderedSequence<TSource>
Remarks
Stable sort. Append thenBy/thenByDescending for multi-key sorting.
Throws
When keySelector is null.
Throws
When keySelector is undefined.
permutations()
permutations():
TyneqSequence<TSource[]>
Defined in: src/types/core.ts:890
Returns all possible permutations of the sequence.
Returns
TyneqSequence<TSource[]>
Remarks
O(n!) time and O(n) auxiliary memory. Use only on short sequences. For a sequence of length n, produces n! result arrays, each of length n.
reverse()
reverse():
TyneqSequence<TSource>
Defined in: src/types/core.ts:893
Returns the sequence in reverse order.
Returns
TyneqSequence<TSource>
shuffle()
shuffle():
TyneqSequence<TSource>
Defined in: src/types/core.ts:901
Returns the sequence in random order using Math.random().
Returns
TyneqSequence<TSource>
Remarks
Uses the Fisher-Yates shuffle. Not cryptographically secure.
backsert()
backsert(
index,other):TyneqSequence<TSource>
Defined in: src/types/core.ts:921
Inserts elements from other into the sequence at index.
Parameters
| Parameter | Type |
|---|---|
index | number |
other | Iterable<TSource> |
Returns
TyneqSequence<TSource>
Remarks
index is zero-based and counts from the end of the sequence. Use 0 to append after the last element, 1 to insert before the last element.
Example
Tyneq.from([1, 2, 3]).backsert(0, [4, 5]).toArray();
// [1, 2, 3, 4, 5] (appended)
Tyneq.from([1, 2, 3]).backsert(1, [99]).toArray();
// [1, 2, 99, 3] (inserted before the last element)Throws
When index is negative.
union()
union(
otherValues):TyneqSequence<TSource>
Defined in: src/types/core.ts:924
Returns the distinct elements from both this sequence and otherValues, using SameValueZero (Set) equality.
Parameters
| Parameter | Type |
|---|---|
otherValues | Iterable<TSource> |
Returns
TyneqSequence<TSource>
unionBy()
unionBy<
TKey>(otherValues,keySelector):TyneqSequence<TSource>
Defined in: src/types/core.ts:932
Returns the elements from both sequences whose keys are distinct.
Type Parameters
| Type Parameter |
|---|
TKey |
Parameters
| Parameter | Type |
|---|---|
otherValues | Iterable<TSource> |
keySelector | (item) => TKey |
Returns
TyneqSequence<TSource>
Throws
When keySelector is null.
Throws
When keySelector is undefined.
pipe()
pipe<
TResult>(factory):TyneqSequence<TResult>
Defined in: src/types/core.ts:950
Passes this sequence through a custom factory function and wraps the result.
Type Parameters
| Type Parameter |
|---|
TResult |
Parameters
| Parameter | Type |
|---|---|
factory | (source) => Enumerator<TResult> | IterableIterator<TResult, any, any> |
Returns
TyneqSequence<TResult>
Remarks
The returned sequence tracks a "pipe" node in the query plan, with factory recorded as the argument. Use this for one-off operator compositions that do not need to be registered via the plugin API.
Throws
When factory is null.
Throws
When factory is undefined.
scan()
scan<
TResult>(seed,accumulator):TyneqSequence<TResult>
Defined in: src/types/core.ts:969
Returns a sequence of running aggregates.
Type Parameters
| Type Parameter |
|---|
TResult |
Parameters
| Parameter | Type |
|---|---|
seed | TResult |
accumulator | (acc, item) => TResult |
Returns
TyneqSequence<TResult>
Remarks
The first element of the output is accumulator(seed, source[0]). Returns an empty sequence when the source is empty.
Throws
When accumulator is null.
Throws
When accumulator is undefined.
minMax()
minMax(
comparer?):MinMaxResult<TSource>
Defined in: src/types/core.ts:979
Returns the minimum and maximum element in one pass.
Parameters
| Parameter | Type |
|---|---|
comparer? | Comparer<TSource> |
Returns
MinMaxResult<TSource>
Remarks
Uses the natural < / > operators when no comparer is provided.
Throws
When the sequence is empty.