iterable-linq-utility 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.cts +132 -0
- package/dist/index.d.ts +132 -0
- package/dist/iterable-linq-utility.js +404 -255
- package/dist/iterable-linq-utility.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,22 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export declare type Action<T> = (value: T, index: number) => Unit;
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Lazily yields the values of `iterable`, then `value`.
|
|
11
|
+
* `value` is yielded only when the source ends, so it is never reached on an infinite source.
|
|
12
|
+
* @operation `Transformation`
|
|
13
|
+
* @param iterable - the source `Iterable`
|
|
14
|
+
* @param value - the value yielded after the last value of the source
|
|
15
|
+
* @returns a lazy, re-runnable `Iterable` of the values of the source followed by `value`
|
|
16
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* Array.from(Functions.append([1, 2, 3], 4)); // [1, 2, 3, 4]
|
|
20
|
+
* ```
|
|
21
|
+
* @since 0.8.0
|
|
22
|
+
*/
|
|
23
|
+
declare function append<T>(iterable: Iterable<T>, value: T): Iterable<T>;
|
|
24
|
+
|
|
9
25
|
/**
|
|
10
26
|
* Callback of `forEachAsync`: an async side effect run on each value.
|
|
11
27
|
* @param value - the current value
|
|
@@ -103,6 +119,23 @@ declare type ComparerFunction<T> = (a: T, b: T) => number;
|
|
|
103
119
|
|
|
104
120
|
declare type ComparingProps<T> = keyof T | Array<keyof T>;
|
|
105
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Lazily yields the values of `iterable`, then the values of each iterable in `others`, in order.
|
|
124
|
+
* Each iterable is opened only when the previous one ends, so the iterables after an infinite one are never read.
|
|
125
|
+
* Stopping early closes only the iterable being read.
|
|
126
|
+
* @operation `Transformation`
|
|
127
|
+
* @param iterable - the source `Iterable`
|
|
128
|
+
* @param others - the iterables read after the source
|
|
129
|
+
* @returns a lazy, re-runnable `Iterable` of the values of the source followed by the values of `others`
|
|
130
|
+
* @throws Error if `iterable` or a value of `others` is missing or does not implement `[Symbol.iterator]`
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* Array.from(Functions.concat([1, 2], [3], new Set([4, 5]))); // [1, 2, 3, 4, 5]
|
|
134
|
+
* ```
|
|
135
|
+
* @since 0.8.0
|
|
136
|
+
*/
|
|
137
|
+
declare function concat<T>(iterable: Iterable<T>, ...others: Iterable<T>[]): Iterable<T>;
|
|
138
|
+
|
|
106
139
|
/**
|
|
107
140
|
* Counts the values of `iterable`; reads the whole source.
|
|
108
141
|
* @operation `Action`
|
|
@@ -451,9 +484,11 @@ export declare function fromRange(start: number, end: number, options?: IRangeOp
|
|
|
451
484
|
|
|
452
485
|
declare namespace Functions {
|
|
453
486
|
export {
|
|
487
|
+
append,
|
|
454
488
|
at,
|
|
455
489
|
average,
|
|
456
490
|
collectToArray,
|
|
491
|
+
concat,
|
|
457
492
|
count,
|
|
458
493
|
distinct,
|
|
459
494
|
empty_2 as empty,
|
|
@@ -476,6 +511,7 @@ declare namespace Functions {
|
|
|
476
511
|
memoize,
|
|
477
512
|
getMemoizeDefaultOptions,
|
|
478
513
|
min,
|
|
514
|
+
prepend,
|
|
479
515
|
range,
|
|
480
516
|
reduce,
|
|
481
517
|
repeat_2 as repeat,
|
|
@@ -483,6 +519,7 @@ declare namespace Functions {
|
|
|
483
519
|
single,
|
|
484
520
|
skip,
|
|
485
521
|
skipWhile,
|
|
522
|
+
slice,
|
|
486
523
|
some,
|
|
487
524
|
sum,
|
|
488
525
|
take,
|
|
@@ -528,6 +565,19 @@ export declare interface IIterableLinqBase<T> {
|
|
|
528
565
|
* @since 0.0.1
|
|
529
566
|
*/
|
|
530
567
|
[Symbol.iterator](): Iterator<T, any, undefined>;
|
|
568
|
+
/**
|
|
569
|
+
* Yields the values of the chain, then `value`.
|
|
570
|
+
* `value` is yielded only when the source ends, so it is never reached on an infinite chain.
|
|
571
|
+
* @operation `Transformation`
|
|
572
|
+
* @param value - the value yielded after the last value of the chain
|
|
573
|
+
* @returns a new chain with the values of this chain followed by `value`
|
|
574
|
+
* @example
|
|
575
|
+
* ```ts
|
|
576
|
+
* IterableLinq.from([1, 2, 3]).append(4).collectToArray(); // [1, 2, 3, 4]
|
|
577
|
+
* ```
|
|
578
|
+
* @since 0.8.0
|
|
579
|
+
*/
|
|
580
|
+
append(value: T): IIterableLinq<T>;
|
|
531
581
|
/**
|
|
532
582
|
* Returns the value at `index`, like `Array.prototype.at`; a negative index counts from the end.
|
|
533
583
|
* A non-negative index runs the chain up to the value, then closes the source; a negative index runs the whole chain,
|
|
@@ -581,6 +631,21 @@ export declare interface IIterableLinqBase<T> {
|
|
|
581
631
|
* @since 0.0.1
|
|
582
632
|
*/
|
|
583
633
|
collectToArray(): T[];
|
|
634
|
+
/**
|
|
635
|
+
* Yields the values of the chain, then the values of each iterable in `others`, in order.
|
|
636
|
+
* Each iterable is opened only when the previous one ends, so the iterables after an infinite chain are never read.
|
|
637
|
+
* Stopping early closes only the iterable being read.
|
|
638
|
+
* @operation `Transformation`
|
|
639
|
+
* @param others - the iterables read after the chain; other chains are iterables too
|
|
640
|
+
* @returns a new chain with the values of this chain followed by the values of `others`
|
|
641
|
+
* @throws Error if a value of `others` is missing or does not implement `[Symbol.iterator]`
|
|
642
|
+
* @example
|
|
643
|
+
* ```ts
|
|
644
|
+
* IterableLinq.from([1, 2]).concat([3], new Set([4, 5])).collectToArray(); // [1, 2, 3, 4, 5]
|
|
645
|
+
* ```
|
|
646
|
+
* @since 0.8.0
|
|
647
|
+
*/
|
|
648
|
+
concat(...others: Iterable<T>[]): IIterableLinq<T>;
|
|
584
649
|
/**
|
|
585
650
|
* Counts the values of the chain; runs the whole chain.
|
|
586
651
|
* @operation `Action`
|
|
@@ -925,6 +990,19 @@ export declare interface IIterableLinqBase<T> {
|
|
|
925
990
|
* @since 0.0.8
|
|
926
991
|
*/
|
|
927
992
|
min(comparer?: Comparer<T>): T | undefined;
|
|
993
|
+
/**
|
|
994
|
+
* Yields `value`, then the values of the chain.
|
|
995
|
+
* `value` is yielded before the source is read.
|
|
996
|
+
* @operation `Transformation`
|
|
997
|
+
* @param value - the value yielded before the first value of the chain
|
|
998
|
+
* @returns a new chain with `value` followed by the values of this chain
|
|
999
|
+
* @example
|
|
1000
|
+
* ```ts
|
|
1001
|
+
* IterableLinq.from([1, 2, 3]).prepend(0).collectToArray(); // [0, 1, 2, 3]
|
|
1002
|
+
* ```
|
|
1003
|
+
* @since 0.8.0
|
|
1004
|
+
*/
|
|
1005
|
+
prepend(value: T): IIterableLinq<T>;
|
|
928
1006
|
/**
|
|
929
1007
|
* Runs the chain and accumulates its values into a single result, starting from the first value.
|
|
930
1008
|
* @operation `Action`
|
|
@@ -1040,6 +1118,24 @@ export declare interface IIterableLinqBase<T> {
|
|
|
1040
1118
|
* @since 0.5.0
|
|
1041
1119
|
*/
|
|
1042
1120
|
skipWhile(predicate: Predicate<T>): IIterableLinq<T>;
|
|
1121
|
+
/**
|
|
1122
|
+
* Yields the values from `start` to `end` (excluded), like `Array.prototype.slice`; a negative index counts from the end.
|
|
1123
|
+
* With non-negative indexes the values are yielded as they are read, and the source is closed at `end`, so `slice` also ends an infinite chain.
|
|
1124
|
+
* A negative `end` yields each value once `-end` more values have been read, keeping only those `-end` values.
|
|
1125
|
+
* A negative `start` runs the whole chain before yielding, keeping only the last `-start` values.
|
|
1126
|
+
* @operation `Transformation`
|
|
1127
|
+
* @param start - an integer, `0` by default; `-1` is the last value
|
|
1128
|
+
* @param end - an integer; the values are yielded up to the end of the chain by default
|
|
1129
|
+
* @returns a new chain with the values from `start` to `end`
|
|
1130
|
+
* @throws Error if `start` or `end` is given and is not an integer (fractions, `NaN` and `Infinity` included)
|
|
1131
|
+
* @example
|
|
1132
|
+
* ```ts
|
|
1133
|
+
* IterableLinq.from([1, 2, 3, 4, 5]).slice(1, 3).collectToArray(); // [2, 3]
|
|
1134
|
+
* IterableLinq.from([1, 2, 3, 4, 5]).slice(-2).collectToArray(); // [4, 5]
|
|
1135
|
+
* ```
|
|
1136
|
+
* @since 0.8.0
|
|
1137
|
+
*/
|
|
1138
|
+
slice(start?: number, end?: number): IIterableLinq<T>;
|
|
1043
1139
|
/**
|
|
1044
1140
|
* Runs the chain until its first value, then stops and closes the source.
|
|
1045
1141
|
* @operation `Action`
|
|
@@ -1408,6 +1504,22 @@ export declare function override<K extends Extract<keyof IIterableLinq<unknown>,
|
|
|
1408
1504
|
*/
|
|
1409
1505
|
export declare type Predicate<T> = (value: T, index: number) => boolean;
|
|
1410
1506
|
|
|
1507
|
+
/**
|
|
1508
|
+
* Lazily yields `value`, then the values of `iterable`.
|
|
1509
|
+
* `value` is yielded before the source is read.
|
|
1510
|
+
* @operation `Transformation`
|
|
1511
|
+
* @param iterable - the source `Iterable`
|
|
1512
|
+
* @param value - the value yielded before the first value of the source
|
|
1513
|
+
* @returns a lazy, re-runnable `Iterable` of `value` followed by the values of the source
|
|
1514
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
|
|
1515
|
+
* @example
|
|
1516
|
+
* ```ts
|
|
1517
|
+
* Array.from(Functions.prepend([1, 2, 3], 0)); // [0, 1, 2, 3]
|
|
1518
|
+
* ```
|
|
1519
|
+
* @since 0.8.0
|
|
1520
|
+
*/
|
|
1521
|
+
declare function prepend<T>(iterable: Iterable<T>, value: T): Iterable<T>;
|
|
1522
|
+
|
|
1411
1523
|
/**
|
|
1412
1524
|
* Returns the numbers from 0 up to, but not including, `end`, computed as `index * step`.
|
|
1413
1525
|
* The direction follows the sign of `end`; `reverse` yields the same numbers backwards; a `NaN` bound gives an empty `Iterable`.
|
|
@@ -1616,6 +1728,26 @@ declare function skip<T>(iterable: Iterable<T>, count: number): Iterable<T>;
|
|
|
1616
1728
|
*/
|
|
1617
1729
|
declare function skipWhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T>;
|
|
1618
1730
|
|
|
1731
|
+
/**
|
|
1732
|
+
* Lazily yields the values from `start` to `end` (excluded), like `Array.prototype.slice`; a negative index counts from the end.
|
|
1733
|
+
* With non-negative indexes the values are yielded as they are read, and the source is closed at `end`, so `slice` also ends an infinite source.
|
|
1734
|
+
* A negative `end` yields each value once `-end` more values have been read, keeping only those `-end` values.
|
|
1735
|
+
* A negative `start` reads the whole source before yielding, keeping only the last `-start` values.
|
|
1736
|
+
* @operation `Transformation`
|
|
1737
|
+
* @param iterable - the source `Iterable`
|
|
1738
|
+
* @param start - an integer, `0` by default; `-1` is the last value
|
|
1739
|
+
* @param end - an integer; the values are yielded up to the end of the source by default
|
|
1740
|
+
* @returns a lazy, re-runnable `Iterable` of the values from `start` to `end`
|
|
1741
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `start` or `end` is given and is not an integer (fractions, `NaN` and `Infinity` included)
|
|
1742
|
+
* @example
|
|
1743
|
+
* ```ts
|
|
1744
|
+
* Array.from(Functions.slice([1, 2, 3, 4, 5], 1, 3)); // [2, 3]
|
|
1745
|
+
* Array.from(Functions.slice([1, 2, 3, 4, 5], -2)); // [4, 5]
|
|
1746
|
+
* ```
|
|
1747
|
+
* @since 0.8.0
|
|
1748
|
+
*/
|
|
1749
|
+
declare function slice<T>(iterable: Iterable<T>, start?: number, end?: number): Iterable<T>;
|
|
1750
|
+
|
|
1619
1751
|
/**
|
|
1620
1752
|
* Tells whether `iterable` contains a value; reads one value, then closes the source.
|
|
1621
1753
|
* @operation `Action`
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,22 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export declare type Action<T> = (value: T, index: number) => Unit;
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Lazily yields the values of `iterable`, then `value`.
|
|
11
|
+
* `value` is yielded only when the source ends, so it is never reached on an infinite source.
|
|
12
|
+
* @operation `Transformation`
|
|
13
|
+
* @param iterable - the source `Iterable`
|
|
14
|
+
* @param value - the value yielded after the last value of the source
|
|
15
|
+
* @returns a lazy, re-runnable `Iterable` of the values of the source followed by `value`
|
|
16
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* Array.from(Functions.append([1, 2, 3], 4)); // [1, 2, 3, 4]
|
|
20
|
+
* ```
|
|
21
|
+
* @since 0.8.0
|
|
22
|
+
*/
|
|
23
|
+
declare function append<T>(iterable: Iterable<T>, value: T): Iterable<T>;
|
|
24
|
+
|
|
9
25
|
/**
|
|
10
26
|
* Callback of `forEachAsync`: an async side effect run on each value.
|
|
11
27
|
* @param value - the current value
|
|
@@ -103,6 +119,23 @@ declare type ComparerFunction<T> = (a: T, b: T) => number;
|
|
|
103
119
|
|
|
104
120
|
declare type ComparingProps<T> = keyof T | Array<keyof T>;
|
|
105
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Lazily yields the values of `iterable`, then the values of each iterable in `others`, in order.
|
|
124
|
+
* Each iterable is opened only when the previous one ends, so the iterables after an infinite one are never read.
|
|
125
|
+
* Stopping early closes only the iterable being read.
|
|
126
|
+
* @operation `Transformation`
|
|
127
|
+
* @param iterable - the source `Iterable`
|
|
128
|
+
* @param others - the iterables read after the source
|
|
129
|
+
* @returns a lazy, re-runnable `Iterable` of the values of the source followed by the values of `others`
|
|
130
|
+
* @throws Error if `iterable` or a value of `others` is missing or does not implement `[Symbol.iterator]`
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* Array.from(Functions.concat([1, 2], [3], new Set([4, 5]))); // [1, 2, 3, 4, 5]
|
|
134
|
+
* ```
|
|
135
|
+
* @since 0.8.0
|
|
136
|
+
*/
|
|
137
|
+
declare function concat<T>(iterable: Iterable<T>, ...others: Iterable<T>[]): Iterable<T>;
|
|
138
|
+
|
|
106
139
|
/**
|
|
107
140
|
* Counts the values of `iterable`; reads the whole source.
|
|
108
141
|
* @operation `Action`
|
|
@@ -451,9 +484,11 @@ export declare function fromRange(start: number, end: number, options?: IRangeOp
|
|
|
451
484
|
|
|
452
485
|
declare namespace Functions {
|
|
453
486
|
export {
|
|
487
|
+
append,
|
|
454
488
|
at,
|
|
455
489
|
average,
|
|
456
490
|
collectToArray,
|
|
491
|
+
concat,
|
|
457
492
|
count,
|
|
458
493
|
distinct,
|
|
459
494
|
empty_2 as empty,
|
|
@@ -476,6 +511,7 @@ declare namespace Functions {
|
|
|
476
511
|
memoize,
|
|
477
512
|
getMemoizeDefaultOptions,
|
|
478
513
|
min,
|
|
514
|
+
prepend,
|
|
479
515
|
range,
|
|
480
516
|
reduce,
|
|
481
517
|
repeat_2 as repeat,
|
|
@@ -483,6 +519,7 @@ declare namespace Functions {
|
|
|
483
519
|
single,
|
|
484
520
|
skip,
|
|
485
521
|
skipWhile,
|
|
522
|
+
slice,
|
|
486
523
|
some,
|
|
487
524
|
sum,
|
|
488
525
|
take,
|
|
@@ -528,6 +565,19 @@ export declare interface IIterableLinqBase<T> {
|
|
|
528
565
|
* @since 0.0.1
|
|
529
566
|
*/
|
|
530
567
|
[Symbol.iterator](): Iterator<T, any, undefined>;
|
|
568
|
+
/**
|
|
569
|
+
* Yields the values of the chain, then `value`.
|
|
570
|
+
* `value` is yielded only when the source ends, so it is never reached on an infinite chain.
|
|
571
|
+
* @operation `Transformation`
|
|
572
|
+
* @param value - the value yielded after the last value of the chain
|
|
573
|
+
* @returns a new chain with the values of this chain followed by `value`
|
|
574
|
+
* @example
|
|
575
|
+
* ```ts
|
|
576
|
+
* IterableLinq.from([1, 2, 3]).append(4).collectToArray(); // [1, 2, 3, 4]
|
|
577
|
+
* ```
|
|
578
|
+
* @since 0.8.0
|
|
579
|
+
*/
|
|
580
|
+
append(value: T): IIterableLinq<T>;
|
|
531
581
|
/**
|
|
532
582
|
* Returns the value at `index`, like `Array.prototype.at`; a negative index counts from the end.
|
|
533
583
|
* A non-negative index runs the chain up to the value, then closes the source; a negative index runs the whole chain,
|
|
@@ -581,6 +631,21 @@ export declare interface IIterableLinqBase<T> {
|
|
|
581
631
|
* @since 0.0.1
|
|
582
632
|
*/
|
|
583
633
|
collectToArray(): T[];
|
|
634
|
+
/**
|
|
635
|
+
* Yields the values of the chain, then the values of each iterable in `others`, in order.
|
|
636
|
+
* Each iterable is opened only when the previous one ends, so the iterables after an infinite chain are never read.
|
|
637
|
+
* Stopping early closes only the iterable being read.
|
|
638
|
+
* @operation `Transformation`
|
|
639
|
+
* @param others - the iterables read after the chain; other chains are iterables too
|
|
640
|
+
* @returns a new chain with the values of this chain followed by the values of `others`
|
|
641
|
+
* @throws Error if a value of `others` is missing or does not implement `[Symbol.iterator]`
|
|
642
|
+
* @example
|
|
643
|
+
* ```ts
|
|
644
|
+
* IterableLinq.from([1, 2]).concat([3], new Set([4, 5])).collectToArray(); // [1, 2, 3, 4, 5]
|
|
645
|
+
* ```
|
|
646
|
+
* @since 0.8.0
|
|
647
|
+
*/
|
|
648
|
+
concat(...others: Iterable<T>[]): IIterableLinq<T>;
|
|
584
649
|
/**
|
|
585
650
|
* Counts the values of the chain; runs the whole chain.
|
|
586
651
|
* @operation `Action`
|
|
@@ -925,6 +990,19 @@ export declare interface IIterableLinqBase<T> {
|
|
|
925
990
|
* @since 0.0.8
|
|
926
991
|
*/
|
|
927
992
|
min(comparer?: Comparer<T>): T | undefined;
|
|
993
|
+
/**
|
|
994
|
+
* Yields `value`, then the values of the chain.
|
|
995
|
+
* `value` is yielded before the source is read.
|
|
996
|
+
* @operation `Transformation`
|
|
997
|
+
* @param value - the value yielded before the first value of the chain
|
|
998
|
+
* @returns a new chain with `value` followed by the values of this chain
|
|
999
|
+
* @example
|
|
1000
|
+
* ```ts
|
|
1001
|
+
* IterableLinq.from([1, 2, 3]).prepend(0).collectToArray(); // [0, 1, 2, 3]
|
|
1002
|
+
* ```
|
|
1003
|
+
* @since 0.8.0
|
|
1004
|
+
*/
|
|
1005
|
+
prepend(value: T): IIterableLinq<T>;
|
|
928
1006
|
/**
|
|
929
1007
|
* Runs the chain and accumulates its values into a single result, starting from the first value.
|
|
930
1008
|
* @operation `Action`
|
|
@@ -1040,6 +1118,24 @@ export declare interface IIterableLinqBase<T> {
|
|
|
1040
1118
|
* @since 0.5.0
|
|
1041
1119
|
*/
|
|
1042
1120
|
skipWhile(predicate: Predicate<T>): IIterableLinq<T>;
|
|
1121
|
+
/**
|
|
1122
|
+
* Yields the values from `start` to `end` (excluded), like `Array.prototype.slice`; a negative index counts from the end.
|
|
1123
|
+
* With non-negative indexes the values are yielded as they are read, and the source is closed at `end`, so `slice` also ends an infinite chain.
|
|
1124
|
+
* A negative `end` yields each value once `-end` more values have been read, keeping only those `-end` values.
|
|
1125
|
+
* A negative `start` runs the whole chain before yielding, keeping only the last `-start` values.
|
|
1126
|
+
* @operation `Transformation`
|
|
1127
|
+
* @param start - an integer, `0` by default; `-1` is the last value
|
|
1128
|
+
* @param end - an integer; the values are yielded up to the end of the chain by default
|
|
1129
|
+
* @returns a new chain with the values from `start` to `end`
|
|
1130
|
+
* @throws Error if `start` or `end` is given and is not an integer (fractions, `NaN` and `Infinity` included)
|
|
1131
|
+
* @example
|
|
1132
|
+
* ```ts
|
|
1133
|
+
* IterableLinq.from([1, 2, 3, 4, 5]).slice(1, 3).collectToArray(); // [2, 3]
|
|
1134
|
+
* IterableLinq.from([1, 2, 3, 4, 5]).slice(-2).collectToArray(); // [4, 5]
|
|
1135
|
+
* ```
|
|
1136
|
+
* @since 0.8.0
|
|
1137
|
+
*/
|
|
1138
|
+
slice(start?: number, end?: number): IIterableLinq<T>;
|
|
1043
1139
|
/**
|
|
1044
1140
|
* Runs the chain until its first value, then stops and closes the source.
|
|
1045
1141
|
* @operation `Action`
|
|
@@ -1408,6 +1504,22 @@ export declare function override<K extends Extract<keyof IIterableLinq<unknown>,
|
|
|
1408
1504
|
*/
|
|
1409
1505
|
export declare type Predicate<T> = (value: T, index: number) => boolean;
|
|
1410
1506
|
|
|
1507
|
+
/**
|
|
1508
|
+
* Lazily yields `value`, then the values of `iterable`.
|
|
1509
|
+
* `value` is yielded before the source is read.
|
|
1510
|
+
* @operation `Transformation`
|
|
1511
|
+
* @param iterable - the source `Iterable`
|
|
1512
|
+
* @param value - the value yielded before the first value of the source
|
|
1513
|
+
* @returns a lazy, re-runnable `Iterable` of `value` followed by the values of the source
|
|
1514
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
|
|
1515
|
+
* @example
|
|
1516
|
+
* ```ts
|
|
1517
|
+
* Array.from(Functions.prepend([1, 2, 3], 0)); // [0, 1, 2, 3]
|
|
1518
|
+
* ```
|
|
1519
|
+
* @since 0.8.0
|
|
1520
|
+
*/
|
|
1521
|
+
declare function prepend<T>(iterable: Iterable<T>, value: T): Iterable<T>;
|
|
1522
|
+
|
|
1411
1523
|
/**
|
|
1412
1524
|
* Returns the numbers from 0 up to, but not including, `end`, computed as `index * step`.
|
|
1413
1525
|
* The direction follows the sign of `end`; `reverse` yields the same numbers backwards; a `NaN` bound gives an empty `Iterable`.
|
|
@@ -1616,6 +1728,26 @@ declare function skip<T>(iterable: Iterable<T>, count: number): Iterable<T>;
|
|
|
1616
1728
|
*/
|
|
1617
1729
|
declare function skipWhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T>;
|
|
1618
1730
|
|
|
1731
|
+
/**
|
|
1732
|
+
* Lazily yields the values from `start` to `end` (excluded), like `Array.prototype.slice`; a negative index counts from the end.
|
|
1733
|
+
* With non-negative indexes the values are yielded as they are read, and the source is closed at `end`, so `slice` also ends an infinite source.
|
|
1734
|
+
* A negative `end` yields each value once `-end` more values have been read, keeping only those `-end` values.
|
|
1735
|
+
* A negative `start` reads the whole source before yielding, keeping only the last `-start` values.
|
|
1736
|
+
* @operation `Transformation`
|
|
1737
|
+
* @param iterable - the source `Iterable`
|
|
1738
|
+
* @param start - an integer, `0` by default; `-1` is the last value
|
|
1739
|
+
* @param end - an integer; the values are yielded up to the end of the source by default
|
|
1740
|
+
* @returns a lazy, re-runnable `Iterable` of the values from `start` to `end`
|
|
1741
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `start` or `end` is given and is not an integer (fractions, `NaN` and `Infinity` included)
|
|
1742
|
+
* @example
|
|
1743
|
+
* ```ts
|
|
1744
|
+
* Array.from(Functions.slice([1, 2, 3, 4, 5], 1, 3)); // [2, 3]
|
|
1745
|
+
* Array.from(Functions.slice([1, 2, 3, 4, 5], -2)); // [4, 5]
|
|
1746
|
+
* ```
|
|
1747
|
+
* @since 0.8.0
|
|
1748
|
+
*/
|
|
1749
|
+
declare function slice<T>(iterable: Iterable<T>, start?: number, end?: number): Iterable<T>;
|
|
1750
|
+
|
|
1619
1751
|
/**
|
|
1620
1752
|
* Tells whether `iterable` contains a value; reads one value, then closes the source.
|
|
1621
1753
|
* @operation `Action`
|