iterable-linq-utility 0.5.0 → 0.6.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 +189 -0
- package/dist/index.d.ts +189 -0
- package/dist/iterable-linq-utility.js +286 -209
- package/dist/iterable-linq-utility.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -15,6 +15,24 @@ export declare type Action<T> = (value: T, index: number) => Unit;
|
|
|
15
15
|
*/
|
|
16
16
|
export declare type AsyncAction<T> = (value: T, index: number) => Promise<Unit>;
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Returns the value at `index`, like `Array.prototype.at`; a negative index counts from the end.
|
|
20
|
+
* A non-negative index reads up to the value, then closes the source; a negative index reads the whole source,
|
|
21
|
+
* keeping only the last `-index` values.
|
|
22
|
+
* @operation `Action`
|
|
23
|
+
* @param iterable - the source `Iterable`
|
|
24
|
+
* @param index - an integer; `-1` is the last value
|
|
25
|
+
* @returns the value at `index`, or `undefined` if `iterable` has no value there
|
|
26
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `index` is not an integer (fractions, `NaN` and `Infinity` included)
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* Functions.at([10, 20, 30], 1); // 20
|
|
30
|
+
* Functions.at([10, 20, 30], -1); // 30
|
|
31
|
+
* ```
|
|
32
|
+
* @since 0.6.0
|
|
33
|
+
*/
|
|
34
|
+
declare function at<T>(iterable: Iterable<T>, index: number): T | undefined;
|
|
35
|
+
|
|
18
36
|
/**
|
|
19
37
|
* Implementation of a method added with `extend` or `override`. `this` is the chain the method is called on.
|
|
20
38
|
* @since 0.1.0
|
|
@@ -241,6 +259,55 @@ declare function find<T>(iterable: Iterable<T>, predicate: Predicate<T>): T | un
|
|
|
241
259
|
*/
|
|
242
260
|
declare function findIndex<T>(iterable: Iterable<T>, predicate: Predicate<T>): number;
|
|
243
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Returns the last value accepted by a type guard, narrowing its type; reads the whole source.
|
|
264
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
265
|
+
* @operation `Action`
|
|
266
|
+
* @param iterable - the source `Iterable`
|
|
267
|
+
* @param predicate - a type guard called with each value and its index
|
|
268
|
+
* @returns the last value accepted by `predicate`, or `undefined` if there is none
|
|
269
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* const values: (number | string)[] = [1, 'two', 3, 'four'];
|
|
273
|
+
* Functions.findLast(values, (v): v is string => typeof v === 'string'); // string | undefined, 'four'
|
|
274
|
+
* ```
|
|
275
|
+
* @since 0.6.0
|
|
276
|
+
*/
|
|
277
|
+
declare function findLast<T, S extends T>(iterable: Iterable<T>, predicate: (value: T, index: number) => value is S): S | undefined;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Returns the last value that satisfies `predicate`; reads the whole source.
|
|
281
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
282
|
+
* @operation `Action`
|
|
283
|
+
* @param iterable - the source `Iterable`
|
|
284
|
+
* @param predicate - called with each value and its index
|
|
285
|
+
* @returns the last value that satisfies `predicate`, or `undefined` if there is none
|
|
286
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* Functions.findLast([1, 5, 6, 2], v => v > 4); // 6
|
|
290
|
+
* ```
|
|
291
|
+
* @since 0.6.0
|
|
292
|
+
*/
|
|
293
|
+
declare function findLast<T>(iterable: Iterable<T>, predicate: Predicate<T>): T | undefined;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Returns the index of the last value that satisfies `predicate`; reads the whole source.
|
|
297
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
298
|
+
* @operation `Action`
|
|
299
|
+
* @param iterable - the source `Iterable`
|
|
300
|
+
* @param predicate - called with each value and its index
|
|
301
|
+
* @returns the index of the last value that satisfies `predicate`, or `-1` if there is none
|
|
302
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* Functions.findLastIndex([1, 5, 6, 2], v => v > 4); // 2
|
|
306
|
+
* ```
|
|
307
|
+
* @since 0.6.0
|
|
308
|
+
*/
|
|
309
|
+
declare function findLastIndex<T>(iterable: Iterable<T>, predicate: Predicate<T>): number;
|
|
310
|
+
|
|
244
311
|
/**
|
|
245
312
|
* Lazily maps each value to an `Iterable` and flattens the results.
|
|
246
313
|
* Each inner `Iterable` is read completely before the next value is mapped.
|
|
@@ -353,6 +420,7 @@ export declare function fromRange(start: number, end: number, options?: IRangeOp
|
|
|
353
420
|
|
|
354
421
|
declare namespace Functions {
|
|
355
422
|
export {
|
|
423
|
+
at,
|
|
356
424
|
collectToArray,
|
|
357
425
|
count,
|
|
358
426
|
distinct,
|
|
@@ -361,10 +429,14 @@ declare namespace Functions {
|
|
|
361
429
|
filter,
|
|
362
430
|
find,
|
|
363
431
|
findIndex,
|
|
432
|
+
findLast,
|
|
433
|
+
findLastIndex,
|
|
364
434
|
flatMap,
|
|
365
435
|
forEach,
|
|
366
436
|
forEachAsync,
|
|
367
437
|
includes,
|
|
438
|
+
indexOf,
|
|
439
|
+
lastIndexOf,
|
|
368
440
|
map,
|
|
369
441
|
materialize,
|
|
370
442
|
max,
|
|
@@ -420,6 +492,22 @@ export declare interface IIterableLinqBase<T> {
|
|
|
420
492
|
* @since 0.0.1
|
|
421
493
|
*/
|
|
422
494
|
[Symbol.iterator](): Iterator<T, any, undefined>;
|
|
495
|
+
/**
|
|
496
|
+
* Returns the value at `index`, like `Array.prototype.at`; a negative index counts from the end.
|
|
497
|
+
* A non-negative index runs the chain up to the value, then closes the source; a negative index runs the whole chain,
|
|
498
|
+
* keeping only the last `-index` values.
|
|
499
|
+
* @operation `Action`
|
|
500
|
+
* @param index - an integer; `-1` is the last value
|
|
501
|
+
* @returns the value at `index`, or `undefined` if the chain has no value there
|
|
502
|
+
* @throws Error if `index` is not an integer (fractions, `NaN` and `Infinity` included)
|
|
503
|
+
* @example
|
|
504
|
+
* ```ts
|
|
505
|
+
* IterableLinq.from([10, 20, 30]).at(1); // 20
|
|
506
|
+
* IterableLinq.from([10, 20, 30]).at(-1); // 30
|
|
507
|
+
* ```
|
|
508
|
+
* @since 0.6.0
|
|
509
|
+
*/
|
|
510
|
+
at(index: number): T | undefined;
|
|
423
511
|
/**
|
|
424
512
|
* Runs the chain and collects its values into an `Array`.
|
|
425
513
|
* @operation `Action`
|
|
@@ -554,6 +642,49 @@ export declare interface IIterableLinqBase<T> {
|
|
|
554
642
|
* @since 0.5.0
|
|
555
643
|
*/
|
|
556
644
|
findIndex(predicate: Predicate<T>): number;
|
|
645
|
+
/**
|
|
646
|
+
* Returns the last value accepted by a type guard, narrowing its type; runs the whole chain.
|
|
647
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
648
|
+
* @operation `Action`
|
|
649
|
+
* @param predicate - a type guard called with each value and its index
|
|
650
|
+
* @returns the last value accepted by `predicate`, or `undefined` if there is none
|
|
651
|
+
* @throws Error if `predicate` is not a function
|
|
652
|
+
* @example
|
|
653
|
+
* ```ts
|
|
654
|
+
* const values: (number | string)[] = [1, 'two', 3, 'four'];
|
|
655
|
+
* IterableLinq.from(values).findLast((v): v is string => typeof v === 'string'); // string | undefined, 'four'
|
|
656
|
+
* ```
|
|
657
|
+
* @since 0.6.0
|
|
658
|
+
*/
|
|
659
|
+
findLast<S extends T>(predicate: (value: T, index: number) => value is S): S | undefined;
|
|
660
|
+
/**
|
|
661
|
+
* Returns the last value that satisfies `predicate`; runs the whole chain.
|
|
662
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
663
|
+
* @operation `Action`
|
|
664
|
+
* @param predicate - called with each value and its index
|
|
665
|
+
* @returns the last value that satisfies `predicate`, or `undefined` if there is none
|
|
666
|
+
* @throws Error if `predicate` is not a function
|
|
667
|
+
* @example
|
|
668
|
+
* ```ts
|
|
669
|
+
* IterableLinq.from([1, 5, 6, 2]).findLast(v => v > 4); // 6
|
|
670
|
+
* ```
|
|
671
|
+
* @since 0.6.0
|
|
672
|
+
*/
|
|
673
|
+
findLast(predicate: Predicate<T>): T | undefined;
|
|
674
|
+
/**
|
|
675
|
+
* Returns the index of the last value that satisfies `predicate`; runs the whole chain.
|
|
676
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
677
|
+
* @operation `Action`
|
|
678
|
+
* @param predicate - called with each value and its index
|
|
679
|
+
* @returns the index of the last value that satisfies `predicate`, or `-1` if there is none
|
|
680
|
+
* @throws Error if `predicate` is not a function
|
|
681
|
+
* @example
|
|
682
|
+
* ```ts
|
|
683
|
+
* IterableLinq.from([1, 5, 6, 2]).findLastIndex(v => v > 4); // 2
|
|
684
|
+
* ```
|
|
685
|
+
* @since 0.6.0
|
|
686
|
+
*/
|
|
687
|
+
findLastIndex(predicate: Predicate<T>): number;
|
|
557
688
|
/**
|
|
558
689
|
* Maps each value to an `Iterable` and flattens the results into one chain.
|
|
559
690
|
* Each inner `Iterable` is read completely before the next value of the chain is mapped.
|
|
@@ -618,6 +749,32 @@ export declare interface IIterableLinqBase<T> {
|
|
|
618
749
|
* @since 0.5.0
|
|
619
750
|
*/
|
|
620
751
|
includes(value: T): boolean;
|
|
752
|
+
/**
|
|
753
|
+
* Returns the index of the first value strictly equal (`===`) to `value`, like `Array.prototype.indexOf`;
|
|
754
|
+
* stops and closes the source at the first match.
|
|
755
|
+
* @operation `Action`
|
|
756
|
+
* @param value - the value to look for; `NaN` is never found, use `includes` or `findIndex` for it
|
|
757
|
+
* @returns the index of the first value equal to `value`, or `-1` if there is none
|
|
758
|
+
* @example
|
|
759
|
+
* ```ts
|
|
760
|
+
* IterableLinq.from([1, 2, 3, 2]).indexOf(2); // 1
|
|
761
|
+
* ```
|
|
762
|
+
* @since 0.6.0
|
|
763
|
+
*/
|
|
764
|
+
indexOf(value: T): number;
|
|
765
|
+
/**
|
|
766
|
+
* Returns the index of the last value strictly equal (`===`) to `value`, like `Array.prototype.lastIndexOf`;
|
|
767
|
+
* runs the whole chain.
|
|
768
|
+
* @operation `Action`
|
|
769
|
+
* @param value - the value to look for; `NaN` is never found, use `findLastIndex` for it
|
|
770
|
+
* @returns the index of the last value equal to `value`, or `-1` if there is none
|
|
771
|
+
* @example
|
|
772
|
+
* ```ts
|
|
773
|
+
* IterableLinq.from([1, 2, 3, 2]).lastIndexOf(2); // 3
|
|
774
|
+
* ```
|
|
775
|
+
* @since 0.6.0
|
|
776
|
+
*/
|
|
777
|
+
lastIndexOf(value: T): number;
|
|
621
778
|
/**
|
|
622
779
|
* Transforms each value with `mapper`.
|
|
623
780
|
* If `mapper` throws, the source is closed and the error propagates.
|
|
@@ -895,6 +1052,22 @@ export declare interface IMemoizeOptions {
|
|
|
895
1052
|
*/
|
|
896
1053
|
declare function includes<T>(iterable: Iterable<T>, value: T): boolean;
|
|
897
1054
|
|
|
1055
|
+
/**
|
|
1056
|
+
* Returns the index of the first value strictly equal (`===`) to `value`, like `Array.prototype.indexOf`;
|
|
1057
|
+
* stops and closes the source at the first match.
|
|
1058
|
+
* @operation `Action`
|
|
1059
|
+
* @param iterable - the source `Iterable`
|
|
1060
|
+
* @param value - the value to look for; `NaN` is never found, use `includes` or `findIndex` for it
|
|
1061
|
+
* @returns the index of the first value equal to `value`, or `-1` if there is none
|
|
1062
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
|
|
1063
|
+
* @example
|
|
1064
|
+
* ```ts
|
|
1065
|
+
* Functions.indexOf([1, 2, 3, 2], 2); // 1
|
|
1066
|
+
* ```
|
|
1067
|
+
* @since 0.6.0
|
|
1068
|
+
*/
|
|
1069
|
+
declare function indexOf<T>(iterable: Iterable<T>, value: T): number;
|
|
1070
|
+
|
|
898
1071
|
/**
|
|
899
1072
|
* Options of `range`.
|
|
900
1073
|
* @since 0.1.0
|
|
@@ -921,6 +1094,22 @@ export declare interface IRangeOptions {
|
|
|
921
1094
|
*/
|
|
922
1095
|
export declare function isIterableLinq(value: unknown): value is IIterableLinq<unknown>;
|
|
923
1096
|
|
|
1097
|
+
/**
|
|
1098
|
+
* Returns the index of the last value strictly equal (`===`) to `value`, like `Array.prototype.lastIndexOf`;
|
|
1099
|
+
* reads the whole source.
|
|
1100
|
+
* @operation `Action`
|
|
1101
|
+
* @param iterable - the source `Iterable`
|
|
1102
|
+
* @param value - the value to look for; `NaN` is never found, use `findLastIndex` for it
|
|
1103
|
+
* @returns the index of the last value equal to `value`, or `-1` if there is none
|
|
1104
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
|
|
1105
|
+
* @example
|
|
1106
|
+
* ```ts
|
|
1107
|
+
* Functions.lastIndexOf([1, 2, 3, 2], 2); // 3
|
|
1108
|
+
* ```
|
|
1109
|
+
* @since 0.6.0
|
|
1110
|
+
*/
|
|
1111
|
+
declare function lastIndexOf<T>(iterable: Iterable<T>, value: T): number;
|
|
1112
|
+
|
|
924
1113
|
/**
|
|
925
1114
|
* Lazily transforms each value with `mapper`.
|
|
926
1115
|
* If `mapper` throws, the source is closed and the error propagates.
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,24 @@ export declare type Action<T> = (value: T, index: number) => Unit;
|
|
|
15
15
|
*/
|
|
16
16
|
export declare type AsyncAction<T> = (value: T, index: number) => Promise<Unit>;
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Returns the value at `index`, like `Array.prototype.at`; a negative index counts from the end.
|
|
20
|
+
* A non-negative index reads up to the value, then closes the source; a negative index reads the whole source,
|
|
21
|
+
* keeping only the last `-index` values.
|
|
22
|
+
* @operation `Action`
|
|
23
|
+
* @param iterable - the source `Iterable`
|
|
24
|
+
* @param index - an integer; `-1` is the last value
|
|
25
|
+
* @returns the value at `index`, or `undefined` if `iterable` has no value there
|
|
26
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `index` is not an integer (fractions, `NaN` and `Infinity` included)
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* Functions.at([10, 20, 30], 1); // 20
|
|
30
|
+
* Functions.at([10, 20, 30], -1); // 30
|
|
31
|
+
* ```
|
|
32
|
+
* @since 0.6.0
|
|
33
|
+
*/
|
|
34
|
+
declare function at<T>(iterable: Iterable<T>, index: number): T | undefined;
|
|
35
|
+
|
|
18
36
|
/**
|
|
19
37
|
* Implementation of a method added with `extend` or `override`. `this` is the chain the method is called on.
|
|
20
38
|
* @since 0.1.0
|
|
@@ -241,6 +259,55 @@ declare function find<T>(iterable: Iterable<T>, predicate: Predicate<T>): T | un
|
|
|
241
259
|
*/
|
|
242
260
|
declare function findIndex<T>(iterable: Iterable<T>, predicate: Predicate<T>): number;
|
|
243
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Returns the last value accepted by a type guard, narrowing its type; reads the whole source.
|
|
264
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
265
|
+
* @operation `Action`
|
|
266
|
+
* @param iterable - the source `Iterable`
|
|
267
|
+
* @param predicate - a type guard called with each value and its index
|
|
268
|
+
* @returns the last value accepted by `predicate`, or `undefined` if there is none
|
|
269
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* const values: (number | string)[] = [1, 'two', 3, 'four'];
|
|
273
|
+
* Functions.findLast(values, (v): v is string => typeof v === 'string'); // string | undefined, 'four'
|
|
274
|
+
* ```
|
|
275
|
+
* @since 0.6.0
|
|
276
|
+
*/
|
|
277
|
+
declare function findLast<T, S extends T>(iterable: Iterable<T>, predicate: (value: T, index: number) => value is S): S | undefined;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Returns the last value that satisfies `predicate`; reads the whole source.
|
|
281
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
282
|
+
* @operation `Action`
|
|
283
|
+
* @param iterable - the source `Iterable`
|
|
284
|
+
* @param predicate - called with each value and its index
|
|
285
|
+
* @returns the last value that satisfies `predicate`, or `undefined` if there is none
|
|
286
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* Functions.findLast([1, 5, 6, 2], v => v > 4); // 6
|
|
290
|
+
* ```
|
|
291
|
+
* @since 0.6.0
|
|
292
|
+
*/
|
|
293
|
+
declare function findLast<T>(iterable: Iterable<T>, predicate: Predicate<T>): T | undefined;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Returns the index of the last value that satisfies `predicate`; reads the whole source.
|
|
297
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
298
|
+
* @operation `Action`
|
|
299
|
+
* @param iterable - the source `Iterable`
|
|
300
|
+
* @param predicate - called with each value and its index
|
|
301
|
+
* @returns the index of the last value that satisfies `predicate`, or `-1` if there is none
|
|
302
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* Functions.findLastIndex([1, 5, 6, 2], v => v > 4); // 2
|
|
306
|
+
* ```
|
|
307
|
+
* @since 0.6.0
|
|
308
|
+
*/
|
|
309
|
+
declare function findLastIndex<T>(iterable: Iterable<T>, predicate: Predicate<T>): number;
|
|
310
|
+
|
|
244
311
|
/**
|
|
245
312
|
* Lazily maps each value to an `Iterable` and flattens the results.
|
|
246
313
|
* Each inner `Iterable` is read completely before the next value is mapped.
|
|
@@ -353,6 +420,7 @@ export declare function fromRange(start: number, end: number, options?: IRangeOp
|
|
|
353
420
|
|
|
354
421
|
declare namespace Functions {
|
|
355
422
|
export {
|
|
423
|
+
at,
|
|
356
424
|
collectToArray,
|
|
357
425
|
count,
|
|
358
426
|
distinct,
|
|
@@ -361,10 +429,14 @@ declare namespace Functions {
|
|
|
361
429
|
filter,
|
|
362
430
|
find,
|
|
363
431
|
findIndex,
|
|
432
|
+
findLast,
|
|
433
|
+
findLastIndex,
|
|
364
434
|
flatMap,
|
|
365
435
|
forEach,
|
|
366
436
|
forEachAsync,
|
|
367
437
|
includes,
|
|
438
|
+
indexOf,
|
|
439
|
+
lastIndexOf,
|
|
368
440
|
map,
|
|
369
441
|
materialize,
|
|
370
442
|
max,
|
|
@@ -420,6 +492,22 @@ export declare interface IIterableLinqBase<T> {
|
|
|
420
492
|
* @since 0.0.1
|
|
421
493
|
*/
|
|
422
494
|
[Symbol.iterator](): Iterator<T, any, undefined>;
|
|
495
|
+
/**
|
|
496
|
+
* Returns the value at `index`, like `Array.prototype.at`; a negative index counts from the end.
|
|
497
|
+
* A non-negative index runs the chain up to the value, then closes the source; a negative index runs the whole chain,
|
|
498
|
+
* keeping only the last `-index` values.
|
|
499
|
+
* @operation `Action`
|
|
500
|
+
* @param index - an integer; `-1` is the last value
|
|
501
|
+
* @returns the value at `index`, or `undefined` if the chain has no value there
|
|
502
|
+
* @throws Error if `index` is not an integer (fractions, `NaN` and `Infinity` included)
|
|
503
|
+
* @example
|
|
504
|
+
* ```ts
|
|
505
|
+
* IterableLinq.from([10, 20, 30]).at(1); // 20
|
|
506
|
+
* IterableLinq.from([10, 20, 30]).at(-1); // 30
|
|
507
|
+
* ```
|
|
508
|
+
* @since 0.6.0
|
|
509
|
+
*/
|
|
510
|
+
at(index: number): T | undefined;
|
|
423
511
|
/**
|
|
424
512
|
* Runs the chain and collects its values into an `Array`.
|
|
425
513
|
* @operation `Action`
|
|
@@ -554,6 +642,49 @@ export declare interface IIterableLinqBase<T> {
|
|
|
554
642
|
* @since 0.5.0
|
|
555
643
|
*/
|
|
556
644
|
findIndex(predicate: Predicate<T>): number;
|
|
645
|
+
/**
|
|
646
|
+
* Returns the last value accepted by a type guard, narrowing its type; runs the whole chain.
|
|
647
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
648
|
+
* @operation `Action`
|
|
649
|
+
* @param predicate - a type guard called with each value and its index
|
|
650
|
+
* @returns the last value accepted by `predicate`, or `undefined` if there is none
|
|
651
|
+
* @throws Error if `predicate` is not a function
|
|
652
|
+
* @example
|
|
653
|
+
* ```ts
|
|
654
|
+
* const values: (number | string)[] = [1, 'two', 3, 'four'];
|
|
655
|
+
* IterableLinq.from(values).findLast((v): v is string => typeof v === 'string'); // string | undefined, 'four'
|
|
656
|
+
* ```
|
|
657
|
+
* @since 0.6.0
|
|
658
|
+
*/
|
|
659
|
+
findLast<S extends T>(predicate: (value: T, index: number) => value is S): S | undefined;
|
|
660
|
+
/**
|
|
661
|
+
* Returns the last value that satisfies `predicate`; runs the whole chain.
|
|
662
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
663
|
+
* @operation `Action`
|
|
664
|
+
* @param predicate - called with each value and its index
|
|
665
|
+
* @returns the last value that satisfies `predicate`, or `undefined` if there is none
|
|
666
|
+
* @throws Error if `predicate` is not a function
|
|
667
|
+
* @example
|
|
668
|
+
* ```ts
|
|
669
|
+
* IterableLinq.from([1, 5, 6, 2]).findLast(v => v > 4); // 6
|
|
670
|
+
* ```
|
|
671
|
+
* @since 0.6.0
|
|
672
|
+
*/
|
|
673
|
+
findLast(predicate: Predicate<T>): T | undefined;
|
|
674
|
+
/**
|
|
675
|
+
* Returns the index of the last value that satisfies `predicate`; runs the whole chain.
|
|
676
|
+
* If `predicate` throws, the source is closed and the error propagates.
|
|
677
|
+
* @operation `Action`
|
|
678
|
+
* @param predicate - called with each value and its index
|
|
679
|
+
* @returns the index of the last value that satisfies `predicate`, or `-1` if there is none
|
|
680
|
+
* @throws Error if `predicate` is not a function
|
|
681
|
+
* @example
|
|
682
|
+
* ```ts
|
|
683
|
+
* IterableLinq.from([1, 5, 6, 2]).findLastIndex(v => v > 4); // 2
|
|
684
|
+
* ```
|
|
685
|
+
* @since 0.6.0
|
|
686
|
+
*/
|
|
687
|
+
findLastIndex(predicate: Predicate<T>): number;
|
|
557
688
|
/**
|
|
558
689
|
* Maps each value to an `Iterable` and flattens the results into one chain.
|
|
559
690
|
* Each inner `Iterable` is read completely before the next value of the chain is mapped.
|
|
@@ -618,6 +749,32 @@ export declare interface IIterableLinqBase<T> {
|
|
|
618
749
|
* @since 0.5.0
|
|
619
750
|
*/
|
|
620
751
|
includes(value: T): boolean;
|
|
752
|
+
/**
|
|
753
|
+
* Returns the index of the first value strictly equal (`===`) to `value`, like `Array.prototype.indexOf`;
|
|
754
|
+
* stops and closes the source at the first match.
|
|
755
|
+
* @operation `Action`
|
|
756
|
+
* @param value - the value to look for; `NaN` is never found, use `includes` or `findIndex` for it
|
|
757
|
+
* @returns the index of the first value equal to `value`, or `-1` if there is none
|
|
758
|
+
* @example
|
|
759
|
+
* ```ts
|
|
760
|
+
* IterableLinq.from([1, 2, 3, 2]).indexOf(2); // 1
|
|
761
|
+
* ```
|
|
762
|
+
* @since 0.6.0
|
|
763
|
+
*/
|
|
764
|
+
indexOf(value: T): number;
|
|
765
|
+
/**
|
|
766
|
+
* Returns the index of the last value strictly equal (`===`) to `value`, like `Array.prototype.lastIndexOf`;
|
|
767
|
+
* runs the whole chain.
|
|
768
|
+
* @operation `Action`
|
|
769
|
+
* @param value - the value to look for; `NaN` is never found, use `findLastIndex` for it
|
|
770
|
+
* @returns the index of the last value equal to `value`, or `-1` if there is none
|
|
771
|
+
* @example
|
|
772
|
+
* ```ts
|
|
773
|
+
* IterableLinq.from([1, 2, 3, 2]).lastIndexOf(2); // 3
|
|
774
|
+
* ```
|
|
775
|
+
* @since 0.6.0
|
|
776
|
+
*/
|
|
777
|
+
lastIndexOf(value: T): number;
|
|
621
778
|
/**
|
|
622
779
|
* Transforms each value with `mapper`.
|
|
623
780
|
* If `mapper` throws, the source is closed and the error propagates.
|
|
@@ -895,6 +1052,22 @@ export declare interface IMemoizeOptions {
|
|
|
895
1052
|
*/
|
|
896
1053
|
declare function includes<T>(iterable: Iterable<T>, value: T): boolean;
|
|
897
1054
|
|
|
1055
|
+
/**
|
|
1056
|
+
* Returns the index of the first value strictly equal (`===`) to `value`, like `Array.prototype.indexOf`;
|
|
1057
|
+
* stops and closes the source at the first match.
|
|
1058
|
+
* @operation `Action`
|
|
1059
|
+
* @param iterable - the source `Iterable`
|
|
1060
|
+
* @param value - the value to look for; `NaN` is never found, use `includes` or `findIndex` for it
|
|
1061
|
+
* @returns the index of the first value equal to `value`, or `-1` if there is none
|
|
1062
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
|
|
1063
|
+
* @example
|
|
1064
|
+
* ```ts
|
|
1065
|
+
* Functions.indexOf([1, 2, 3, 2], 2); // 1
|
|
1066
|
+
* ```
|
|
1067
|
+
* @since 0.6.0
|
|
1068
|
+
*/
|
|
1069
|
+
declare function indexOf<T>(iterable: Iterable<T>, value: T): number;
|
|
1070
|
+
|
|
898
1071
|
/**
|
|
899
1072
|
* Options of `range`.
|
|
900
1073
|
* @since 0.1.0
|
|
@@ -921,6 +1094,22 @@ export declare interface IRangeOptions {
|
|
|
921
1094
|
*/
|
|
922
1095
|
export declare function isIterableLinq(value: unknown): value is IIterableLinq<unknown>;
|
|
923
1096
|
|
|
1097
|
+
/**
|
|
1098
|
+
* Returns the index of the last value strictly equal (`===`) to `value`, like `Array.prototype.lastIndexOf`;
|
|
1099
|
+
* reads the whole source.
|
|
1100
|
+
* @operation `Action`
|
|
1101
|
+
* @param iterable - the source `Iterable`
|
|
1102
|
+
* @param value - the value to look for; `NaN` is never found, use `findLastIndex` for it
|
|
1103
|
+
* @returns the index of the last value equal to `value`, or `-1` if there is none
|
|
1104
|
+
* @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
|
|
1105
|
+
* @example
|
|
1106
|
+
* ```ts
|
|
1107
|
+
* Functions.lastIndexOf([1, 2, 3, 2], 2); // 3
|
|
1108
|
+
* ```
|
|
1109
|
+
* @since 0.6.0
|
|
1110
|
+
*/
|
|
1111
|
+
declare function lastIndexOf<T>(iterable: Iterable<T>, value: T): number;
|
|
1112
|
+
|
|
924
1113
|
/**
|
|
925
1114
|
* Lazily transforms each value with `mapper`.
|
|
926
1115
|
* If `mapper` throws, the source is closed and the error propagates.
|