tyneq / Tyneq
Class: Tyneq
Defined in: src/core/tyneq.ts:29
Entry point for creating Tyneq sequences.
Example
import { Tyneq } from "tyneq";
const sum = Tyneq.from([1, 2, 3, 4, 5])
.where((x) => x % 2 === 0)
.sum((x) => x); // -> 6Constructors
Constructor
new Tyneq():
Tyneq
Returns
Tyneq
Methods
from()
staticfrom<TSource>(source):TyneqSequence<TSource>
Defined in: src/core/tyneq.ts:37
Creates a lazy sequence from any Iterable<T> (arrays, sets, generators, etc.).
Type Parameters
| Type Parameter |
|---|
TSource |
Parameters
| Parameter | Type |
|---|---|
source | Iterable<TSource> |
Returns
TyneqSequence<TSource>
Throws
When source is null or undefined.
Throws
When source is not iterable.
random()
staticrandom<TSource>(count,randomizer):TyneqSequence<TSource>
Defined in: src/core/tyneq.ts:65
Creates a sequence of count elements produced by calling randomizer once per element.
Type Parameters
| Type Parameter |
|---|
TSource |
Parameters
| Parameter | Type |
|---|---|
count | number |
randomizer | () => TSource |
Returns
TyneqSequence<TSource>
Remarks
Returns an empty sequence when count === 0.
Throws
When count is negative.
Throws
When randomizer is null or undefined.
isNullOrEmpty()
staticisNullOrEmpty<TSource>(source):boolean
Defined in: src/core/tyneq.ts:78
Returns true if source is null, undefined, or an iterable whose first element is null or undefined.
Type Parameters
| Type Parameter |
|---|
TSource |
Parameters
| Parameter | Type |
|---|---|
source | Optional<Iterable<TSource, any, any>> |
Returns
boolean
range()
staticrange(start,count):TyneqSequence<number>
Defined in: src/core/tyneq.ts:101
Creates a sequence of count integers starting from start.
Parameters
| Parameter | Type |
|---|---|
start | number |
count | number |
Returns
TyneqSequence<number>
Remarks
Returns an empty sequence when count === 0.
Example
Tyneq.range(1, 5).toArray(); // -> [1, 2, 3, 4, 5]Throws
When count is negative.
Throws
When count is not an integer.
empty()
staticempty<TSource>():TyneqSequence<TSource>
Defined in: src/core/tyneq.ts:113
Returns an empty sequence with zero elements.
Type Parameters
| Type Parameter |
|---|
TSource |
Returns
TyneqSequence<TSource>
repeat()
staticrepeat<TSource>(value,count):TyneqSequence<TSource>
Defined in: src/core/tyneq.ts:132
Creates a sequence that yields value exactly count times.
Type Parameters
| Type Parameter |
|---|
TSource |
Parameters
| Parameter | Type |
|---|---|
value | TSource |
count | number |
Returns
TyneqSequence<TSource>
Example
Tyneq.repeat("x", 3).toArray(); // -> ["x", "x", "x"]Throws
When count is negative.
Throws
When count is not an integer.
generate()
staticgenerate<TSource,TResult>(seed,next,count?):TyneqSequence<TResult>
Defined in: src/core/tyneq.ts:158
Creates a sequence by repeatedly applying next to produce each element from the previous one.
Type Parameters
| Type Parameter |
|---|
TSource |
TResult |
Parameters
| Parameter | Type |
|---|---|
seed | TSource |
next | ItemSelector<TSource, TResult> |
count? | number |
Returns
TyneqSequence<TResult>
Remarks
The selector receives (currentValue, index). Each call's return value becomes the input for the next call. Omit count for an infinite sequence; pair with take to bound it.
Example
Tyneq.generate(1, (x) => x * 2, 4).toArray(); // -> [2, 4, 8, 16]Throws
When next is null or undefined.
Throws
When count is negative.
Throws
When count is not an integer.
concat()
staticconcat<TSource>(...sources):TyneqSequence<TSource>
Defined in: src/core/tyneq.ts:185
Creates a sequence that yields all elements from each source in order.
Type Parameters
| Type Parameter |
|---|
TSource |
Parameters
| Parameter | Type |
|---|---|
...sources | Iterable<TSource, any, any>[] |
Returns
TyneqSequence<TSource>
Remarks
Returns an empty sequence when called with no arguments.
Example
Tyneq.concat([1, 2], [3, 4], [5]).toArray(); // -> [1, 2, 3, 4, 5]Throws
When any source is null or undefined.
Throws
When any source is not iterable.
enumerate()
staticenumerate<TSource>(source):TyneqSequence<[number,TSource]>
Defined in: src/core/tyneq.ts:211
Pairs each element with its zero-based index.
Type Parameters
| Type Parameter |
|---|
TSource |
Parameters
| Parameter | Type |
|---|---|
source | Iterable<TSource> |
Returns
TyneqSequence<[number, TSource]>
Remarks
Each iteration produces independent index counters - safe to re-enumerate.
Example
Tyneq.enumerate(["a", "b", "c"]).toArray();
// -> [[0, "a"], [1, "b"], [2, "c"]]Throws
When source is null or undefined.
Throws
When source is not iterable.