iterable-linq-utility 0.3.0 → 0.5.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/README.md CHANGED
@@ -1,6 +1,9 @@
1
- [![](https://data.jsdelivr.com/v1/package/npm/iterable-linq-utility/badge)](https://www.jsdelivr.com/package/npm/iterable-linq-utility)
2
- [![](https://img.shields.io/npm/v/iterable-linq-utility.svg)](https://npmjs.org/package/iterable-linq-utility)
3
- [![](https://img.shields.io/npm/dm/iterable-linq-utility.svg)](https://npmjs.org/package/iterable-linq-utility)
1
+ | | |
2
+ | --- | --- |
3
+ | **Package** | [![npm version](https://img.shields.io/npm/v/iterable-linq-utility.svg)](https://npmjs.org/package/iterable-linq-utility) [![npm downloads](https://img.shields.io/npm/dm/iterable-linq-utility.svg)](https://npmjs.org/package/iterable-linq-utility) [![jsDelivr hits](https://data.jsdelivr.com/v1/package/npm/iterable-linq-utility/badge)](https://www.jsdelivr.com/package/npm/iterable-linq-utility) |
4
+ | **Quality** | [![CI status](https://github.com/Amebus/iterable-linq-utility/actions/workflows/build-test.yml/badge.svg?branch=main&event=push)](https://github.com/Amebus/iterable-linq-utility/actions/workflows/build-test.yml?query=branch%3Amain+event%3Apush) [![Coverage](https://codecov.io/gh/Amebus/iterable-linq-utility/branch/main/graph/badge.svg)](https://codecov.io/gh/Amebus/iterable-linq-utility) |
5
+ | **Activity** | [![Commits since the latest release](https://img.shields.io/github/commits-since/Amebus/iterable-linq-utility/latest)](https://amebus.github.io/iterable-linq-utility/next/) [![Latest release date](https://img.shields.io/github/release-date/Amebus/iterable-linq-utility)](https://github.com/Amebus/iterable-linq-utility/releases/latest) [![Open issues](https://img.shields.io/github/issues/Amebus/iterable-linq-utility)](https://github.com/Amebus/iterable-linq-utility/issues) [![Open pull requests](https://img.shields.io/github/issues-pr/Amebus/iterable-linq-utility)](https://github.com/Amebus/iterable-linq-utility/pulls) |
6
+ | **Community** | [![GitHub stars](https://img.shields.io/github/stars/Amebus/iterable-linq-utility)](https://github.com/Amebus/iterable-linq-utility/stargazers) [![Forks](https://img.shields.io/github/forks/Amebus/iterable-linq-utility)](https://github.com/Amebus/iterable-linq-utility/forks) |
4
7
 
5
8
  A [.NET Linq to Objects](https://learn.microsoft.com/it-it/dotnet/csharp/programming-guide/concepts/linq/linq-to-objects) porting with javacript naming conventions (e.g.: `Select` as been ranamed to `map`) and some new features (e.g.: [memoize](https://amebus.github.io/iterable-linq-utility/api-reference/transformations.md#memoize) and [materialize](https://amebus.github.io/iterable-linq-utility/api-reference/actions.md#materialize)).
6
9
 
@@ -85,11 +88,11 @@ A difference smaller than the `rme` of the two rows is noise.
85
88
  Create `test/bench/functions/<name>.bench.ts` or `test/bench/chains/<scenario>.bench.ts`:
86
89
 
87
90
  ```ts
88
- import * as IterableLinq from 'iterable-linq-utility';
89
91
  import { test } from 'vitest';
90
-
91
92
  import * as Helpers from '../helpers';
92
93
 
94
+ import * as IterableLinq from 'iterable-linq-utility';
95
+
93
96
  // Read the exports once: an imported binding goes through a module runner getter on every read.
94
97
  const { from } = IterableLinq;
95
98
  const { cases, numbers, sum } = Helpers;
package/dist/index.d.cts CHANGED
@@ -54,6 +54,54 @@ declare type ComparerFunction<T> = (a: T, b: T) => number;
54
54
 
55
55
  declare type ComparingProps<T> = keyof T | Array<keyof T>;
56
56
 
57
+ /**
58
+ * Counts the values of `iterable`; reads the whole source.
59
+ * @operation `Action`
60
+ * @param iterable - the source `Iterable`
61
+ * @returns the number of values in `iterable`
62
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
63
+ * @example
64
+ * ```ts
65
+ * Functions.count([1, 2, 3]); // 3
66
+ * ```
67
+ * @since 0.5.0
68
+ */
69
+ declare function count<T>(iterable: Iterable<T>): number;
70
+
71
+ /**
72
+ * Counts the values that satisfy `predicate`; reads the whole source.
73
+ * If `predicate` throws, the source is closed and the error propagates.
74
+ * @operation `Action`
75
+ * @param iterable - the source `Iterable`
76
+ * @param predicate - called with each value and its index; `undefined` counts every value
77
+ * @returns the number of values that satisfy `predicate`
78
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if a provided `predicate` is not a function
79
+ * @example
80
+ * ```ts
81
+ * Functions.count([1, 5, 2, 6], v => v > 4); // 2
82
+ * ```
83
+ * @since 0.5.0
84
+ */
85
+ declare function count<T>(iterable: Iterable<T>, predicate: Predicate<T> | undefined): number;
86
+
87
+ /**
88
+ * Lazily yields the first value for each distinct value or selected key, in source order.
89
+ * Keys use `SameValueZero`, like `Set`; original values are preserved.
90
+ * Each iterator stores its own seen keys. If `keySelector` throws, the source is closed and the error propagates.
91
+ * @operation `Transformation`
92
+ * @param iterable - the source `Iterable`
93
+ * @param keySelector - called with every source value and its index; omitted or `undefined` compares values directly
94
+ * @returns a lazy, re-runnable `Iterable` of the first values for each key
95
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if a provided `keySelector` is not a function
96
+ * @example
97
+ * ```ts
98
+ * Array.from(Functions.distinct([3, 1, 3, 2, 1])); // [3, 1, 2]
99
+ * Array.from(Functions.distinct([{ id: 1 }, { id: 1 }, { id: 2 }], v => v.id)); // [{ id: 1 }, { id: 2 }]
100
+ * ```
101
+ * @since 0.5.0
102
+ */
103
+ declare function distinct<T, K>(iterable: Iterable<T>, keySelector?: Mapper<T, K>): Iterable<T>;
104
+
57
105
  /**
58
106
  * Starts a chain with no values.
59
107
  * @returns an empty chain
@@ -77,6 +125,21 @@ export declare function empty<T>(): IIterableLinq<T>;
77
125
  */
78
126
  declare function empty_2<T>(): Iterable<T>;
79
127
 
128
+ /**
129
+ * Tells whether every value satisfies `predicate`; stops and closes the source at the first rejected value.
130
+ * @operation `Action`
131
+ * @param iterable - the source `Iterable`
132
+ * @param predicate - called with each value and its index
133
+ * @returns `true` if every value satisfies `predicate`, or if `iterable` is empty; `false` otherwise
134
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
135
+ * @example
136
+ * ```ts
137
+ * Functions.every([1, 2, 3], v => v > 0); // true
138
+ * ```
139
+ * @since 0.5.0
140
+ */
141
+ declare function every<T>(iterable: Iterable<T>, predicate: Predicate<T>): boolean;
142
+
80
143
  /**
81
144
  * Adds a method to every chain, including the chains created before the call.
82
145
  * Declare the method first by augmenting `IIterableLinq`, then register it once, at application start-up.
@@ -98,6 +161,24 @@ declare function empty_2<T>(): Iterable<T>;
98
161
  */
99
162
  export declare function extend<K extends Extract<keyof IIterableLinq<unknown>, string>>(name: K, implementation: ChainMethod): void;
100
163
 
164
+ /**
165
+ * Lazily keeps the values accepted by a type guard and narrows their type.
166
+ * If `predicate` throws, the source is closed and the error propagates.
167
+ * @operation `Transformation`
168
+ * @param iterable - the source `Iterable`
169
+ * @param predicate - a type guard called with each value and its index; return `true` to keep the value
170
+ * @returns a lazy, re-runnable `Iterable` of the narrowed values
171
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
172
+ * @example
173
+ * ```ts
174
+ * const values: (number | string)[] = [1, 'two', 3];
175
+ * const strings = Functions.filter(values, (v): v is string => typeof v === 'string');
176
+ * Array.from(strings); // string[], ['two']
177
+ * ```
178
+ * @since 0.4.0
179
+ */
180
+ declare function filter<T, S extends T>(iterable: Iterable<T>, predicate: (value: T, index: number) => value is S): Iterable<S>;
181
+
101
182
  /**
102
183
  * Lazily keeps only the values that satisfy `predicate`.
103
184
  * If `predicate` throws, the source is closed and the error propagates.
@@ -114,6 +195,52 @@ export declare function extend<K extends Extract<keyof IIterableLinq<unknown>, s
114
195
  */
115
196
  declare function filter<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T>;
116
197
 
198
+ /**
199
+ * Returns the first value accepted by a type guard, narrowing its type; stops and closes the source at the first match.
200
+ * @operation `Action`
201
+ * @param iterable - the source `Iterable`
202
+ * @param predicate - a type guard called with each value and its index
203
+ * @returns the first value accepted by `predicate`, or `undefined` if there is none
204
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
205
+ * @example
206
+ * ```ts
207
+ * const values: (number | string)[] = [1, 'two', 3];
208
+ * Functions.find(values, (v): v is string => typeof v === 'string'); // string | undefined, 'two'
209
+ * ```
210
+ * @since 0.5.0
211
+ */
212
+ declare function find<T, S extends T>(iterable: Iterable<T>, predicate: (value: T, index: number) => value is S): S | undefined;
213
+
214
+ /**
215
+ * Returns the first value that satisfies `predicate`; stops and closes the source at the first match.
216
+ * @operation `Action`
217
+ * @param iterable - the source `Iterable`
218
+ * @param predicate - called with each value and its index
219
+ * @returns the first value that satisfies `predicate`, or `undefined` if there is none
220
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
221
+ * @example
222
+ * ```ts
223
+ * Functions.find([1, 5, 6], v => v > 4); // 5
224
+ * ```
225
+ * @since 0.5.0
226
+ */
227
+ declare function find<T>(iterable: Iterable<T>, predicate: Predicate<T>): T | undefined;
228
+
229
+ /**
230
+ * Returns the index of the first value that satisfies `predicate`; stops and closes the source at the first match.
231
+ * @operation `Action`
232
+ * @param iterable - the source `Iterable`
233
+ * @param predicate - called with each value and its index
234
+ * @returns the index of the first value that satisfies `predicate`, or `-1` if there is none
235
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
236
+ * @example
237
+ * ```ts
238
+ * Functions.findIndex([1, 5, 6], v => v > 4); // 1
239
+ * ```
240
+ * @since 0.5.0
241
+ */
242
+ declare function findIndex<T>(iterable: Iterable<T>, predicate: Predicate<T>): number;
243
+
117
244
  /**
118
245
  * Lazily maps each value to an `Iterable` and flattens the results.
119
246
  * Each inner `Iterable` is read completely before the next value is mapped.
@@ -227,11 +354,17 @@ export declare function fromRange(start: number, end: number, options?: IRangeOp
227
354
  declare namespace Functions {
228
355
  export {
229
356
  collectToArray,
357
+ count,
358
+ distinct,
230
359
  empty_2 as empty,
360
+ every,
231
361
  filter,
362
+ find,
363
+ findIndex,
232
364
  flatMap,
233
365
  forEach,
234
366
  forEachAsync,
367
+ includes,
235
368
  map,
236
369
  materialize,
237
370
  max,
@@ -242,8 +375,10 @@ declare namespace Functions {
242
375
  reduce,
243
376
  repeat_2 as repeat,
244
377
  skip,
378
+ skipWhile,
245
379
  some,
246
380
  take,
381
+ takeWhile,
247
382
  tap,
248
383
  tapChain
249
384
  }
@@ -296,6 +431,75 @@ export declare interface IIterableLinqBase<T> {
296
431
  * @since 0.0.1
297
432
  */
298
433
  collectToArray(): T[];
434
+ /**
435
+ * Counts the values of the chain; runs the whole chain.
436
+ * @operation `Action`
437
+ * @returns the number of values in the chain
438
+ * @example
439
+ * ```ts
440
+ * IterableLinq.from([1, 2, 3]).count(); // 3
441
+ * ```
442
+ * @since 0.5.0
443
+ */
444
+ count(): number;
445
+ /**
446
+ * Counts the values that satisfy `predicate`; runs the whole chain.
447
+ * If `predicate` throws, the source is closed and the error propagates.
448
+ * @operation `Action`
449
+ * @param predicate - called with each value and its index; `undefined` counts every value
450
+ * @returns the number of values that satisfy `predicate`
451
+ * @throws Error if a provided `predicate` is not a function
452
+ * @example
453
+ * ```ts
454
+ * IterableLinq.from([1, 5, 2, 6]).count(v => v > 4); // 2
455
+ * ```
456
+ * @since 0.5.0
457
+ */
458
+ count(predicate: Predicate<T> | undefined): number;
459
+ /**
460
+ * Yields the first value for each distinct value or selected key, in source order.
461
+ * Keys use `SameValueZero`, like `Set`; original values are preserved.
462
+ * Each iteration stores its own seen keys. If `keySelector` throws, the source is closed and the error propagates.
463
+ * @operation `Transformation`
464
+ * @param keySelector - called with every source value and its index; omitted or `undefined` compares values directly
465
+ * @returns a new lazy, re-runnable chain of the first values for each key
466
+ * @throws Error if a provided `keySelector` is not a function
467
+ * @example
468
+ * ```ts
469
+ * IterableLinq.from([3, 1, 3, 2, 1]).distinct().collectToArray(); // [3, 1, 2]
470
+ * IterableLinq.from([{ id: 1 }, { id: 1 }, { id: 2 }]).distinct(v => v.id).collectToArray(); // [{ id: 1 }, { id: 2 }]
471
+ * ```
472
+ * @since 0.5.0
473
+ */
474
+ distinct<K>(keySelector?: Mapper<T, K>): IIterableLinq<T>;
475
+ /**
476
+ * Tells whether every value satisfies `predicate`; stops and closes the source at the first rejected value.
477
+ * @operation `Action`
478
+ * @param predicate - called with each value and its index
479
+ * @returns `true` if every value satisfies `predicate`, or if the chain is empty; `false` otherwise
480
+ * @throws Error if `predicate` is not a function
481
+ * @example
482
+ * ```ts
483
+ * IterableLinq.from([1, 2, 3]).every(v => v > 0); // true
484
+ * ```
485
+ * @since 0.5.0
486
+ */
487
+ every(predicate: Predicate<T>): boolean;
488
+ /**
489
+ * Keeps the values accepted by a type guard and narrows their type.
490
+ * If `predicate` throws, the source is closed and the error propagates.
491
+ * @operation `Transformation`
492
+ * @param predicate - a type guard called with each value and its index; return `true` to keep the value
493
+ * @returns a new chain with the narrowed values
494
+ * @throws Error if `predicate` is not a function
495
+ * @example
496
+ * ```ts
497
+ * const values: (number | string)[] = [1, 'two', 3];
498
+ * IterableLinq.from(values).filter((v): v is string => typeof v === 'string').collectToArray(); // string[], ['two']
499
+ * ```
500
+ * @since 0.4.0
501
+ */
502
+ filter<S extends T>(predicate: (value: T, index: number) => value is S): IIterableLinq<S>;
299
503
  /**
300
504
  * Keeps only the values that satisfy `predicate`.
301
505
  * If `predicate` throws, the source is closed and the error propagates.
@@ -310,6 +514,46 @@ export declare interface IIterableLinqBase<T> {
310
514
  * @since 0.0.1
311
515
  */
312
516
  filter(predicate: Predicate<T>): IIterableLinq<T>;
517
+ /**
518
+ * Returns the first value accepted by a type guard, narrowing its type; stops and closes the source at the first match.
519
+ * @operation `Action`
520
+ * @param predicate - a type guard called with each value and its index
521
+ * @returns the first value accepted by `predicate`, or `undefined` if there is none
522
+ * @throws Error if `predicate` is not a function
523
+ * @example
524
+ * ```ts
525
+ * const values: (number | string)[] = [1, 'two', 3];
526
+ * IterableLinq.from(values).find((v): v is string => typeof v === 'string'); // string | undefined, 'two'
527
+ * ```
528
+ * @since 0.5.0
529
+ */
530
+ find<S extends T>(predicate: (value: T, index: number) => value is S): S | undefined;
531
+ /**
532
+ * Returns the first value that satisfies `predicate`; stops and closes the source at the first match.
533
+ * @operation `Action`
534
+ * @param predicate - called with each value and its index
535
+ * @returns the first value that satisfies `predicate`, or `undefined` if there is none
536
+ * @throws Error if `predicate` is not a function
537
+ * @example
538
+ * ```ts
539
+ * IterableLinq.from([1, 5, 6]).find(v => v > 4); // 5
540
+ * ```
541
+ * @since 0.5.0
542
+ */
543
+ find(predicate: Predicate<T>): T | undefined;
544
+ /**
545
+ * Returns the index of the first value that satisfies `predicate`; stops and closes the source at the first match.
546
+ * @operation `Action`
547
+ * @param predicate - called with each value and its index
548
+ * @returns the index of the first value that satisfies `predicate`, or `-1` if there is none
549
+ * @throws Error if `predicate` is not a function
550
+ * @example
551
+ * ```ts
552
+ * IterableLinq.from([1, 5, 6]).findIndex(v => v > 4); // 1
553
+ * ```
554
+ * @since 0.5.0
555
+ */
556
+ findIndex(predicate: Predicate<T>): number;
313
557
  /**
314
558
  * Maps each value to an `Iterable` and flattens the results into one chain.
315
559
  * Each inner `Iterable` is read completely before the next value of the chain is mapped.
@@ -361,6 +605,19 @@ export declare interface IIterableLinqBase<T> {
361
605
  * @since 0.0.11
362
606
  */
363
607
  forEachAsync(action: AsyncAction<T>): Promise<Unit>;
608
+ /**
609
+ * Tells whether the chain contains `value`, compared with `SameValueZero` like `Array.prototype.includes`;
610
+ * stops and closes the source at the first match.
611
+ * @operation `Action`
612
+ * @param value - the value to look for; `NaN` matches `NaN`, and `+0` matches `-0`
613
+ * @returns `true` if the chain contains `value`; `false` otherwise
614
+ * @example
615
+ * ```ts
616
+ * IterableLinq.from([1, 2, NaN]).includes(NaN); // true
617
+ * ```
618
+ * @since 0.5.0
619
+ */
620
+ includes(value: T): boolean;
364
621
  /**
365
622
  * Transforms each value with `mapper`.
366
623
  * If `mapper` throws, the source is closed and the error propagates.
@@ -475,6 +732,21 @@ export declare interface IIterableLinqBase<T> {
475
732
  * @since 0.3.0
476
733
  */
477
734
  skip(count: number): IIterableLinq<T>;
735
+ /**
736
+ * Skips the values while `predicate` returns `true`, then yields the first rejected value and all the rest.
737
+ * After the first rejected value, `predicate` is not called again.
738
+ * If `predicate` throws, the source is closed and the error propagates.
739
+ * @operation `Transformation`
740
+ * @param predicate - called with each value and its index until it returns `false`
741
+ * @returns a new chain of the values from the first rejected one
742
+ * @throws Error if `predicate` is not a function
743
+ * @example
744
+ * ```ts
745
+ * IterableLinq.from([1, 2, 5, 3]).skipWhile(v => v < 4).collectToArray(); // [5, 3]
746
+ * ```
747
+ * @since 0.5.0
748
+ */
749
+ skipWhile(predicate: Predicate<T>): IIterableLinq<T>;
478
750
  /**
479
751
  * Runs the chain until its first value, then stops and closes the source.
480
752
  * @operation `Action`
@@ -513,6 +785,37 @@ export declare interface IIterableLinqBase<T> {
513
785
  * @since 0.3.0
514
786
  */
515
787
  take(count: number): IIterableLinq<T>;
788
+ /**
789
+ * Yields the values while a type guard accepts them, narrowing their type, then closes the source.
790
+ * The source is never read past the first rejected value, which is not yielded.
791
+ * If `predicate` throws, the source is closed and the error propagates.
792
+ * @operation `Transformation`
793
+ * @param predicate - a type guard called with each value and its index; the first `false` ends the chain
794
+ * @returns a new chain of the narrowed values before the first rejected one
795
+ * @throws Error if `predicate` is not a function
796
+ * @example
797
+ * ```ts
798
+ * const values: (number | string)[] = [1, 2, 'three', 4];
799
+ * IterableLinq.from(values).takeWhile((v): v is number => typeof v === 'number').collectToArray(); // number[], [1, 2]
800
+ * ```
801
+ * @since 0.5.0
802
+ */
803
+ takeWhile<S extends T>(predicate: (value: T, index: number) => value is S): IIterableLinq<S>;
804
+ /**
805
+ * Yields the values while `predicate` returns `true`, then closes the source.
806
+ * The source is never read past the first rejected value, which is not yielded, so `takeWhile` can end an infinite chain.
807
+ * If `predicate` throws, the source is closed and the error propagates.
808
+ * @operation `Transformation`
809
+ * @param predicate - called with each value and its index; the first `false` ends the chain
810
+ * @returns a new chain of the values before the first rejected one
811
+ * @throws Error if `predicate` is not a function
812
+ * @example
813
+ * ```ts
814
+ * IterableLinq.from([1, 2, 5, 3]).takeWhile(v => v < 4).collectToArray(); // [1, 2]
815
+ * ```
816
+ * @since 0.5.0
817
+ */
818
+ takeWhile(predicate: Predicate<T>): IIterableLinq<T>;
516
819
  /**
517
820
  * Calls `tapper` on each value as it flows through the chain, without changing it.
518
821
  * If `tapper` throws, the source is closed and the error propagates.
@@ -555,11 +858,12 @@ export declare interface IIterableLinqBase<T> {
555
858
  * @example
556
859
  * ```ts
557
860
  * let evens: IIterableLinq<number> | undefined;
558
- * IterableLinq.fromRange(10)
861
+ * const evensByTen = IterableLinq.fromRange(10)
559
862
  * .filter(v => v % 2 === 0)
560
863
  * .tapChainCreation(chain => { evens = chain; return unit(); })
561
864
  * .map(v => v * 10);
562
865
  * evens?.collectToArray(); // [0, 2, 4, 6, 8]
866
+ * evensByTen.collectToArray(); // [0, 20, 40, 60, 80]
563
867
  * ```
564
868
  * @since 0.0.10
565
869
  */
@@ -575,6 +879,22 @@ export declare interface IMemoizeOptions {
575
879
  allowPartialMemoization?: boolean;
576
880
  }
577
881
 
882
+ /**
883
+ * Tells whether `iterable` contains `value`, compared with `SameValueZero` like `Array.prototype.includes`;
884
+ * stops and closes the source at the first match.
885
+ * @operation `Action`
886
+ * @param iterable - the source `Iterable`
887
+ * @param value - the value to look for; `NaN` matches `NaN`, and `+0` matches `-0`
888
+ * @returns `true` if `iterable` contains `value`; `false` otherwise
889
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
890
+ * @example
891
+ * ```ts
892
+ * Functions.includes([1, 2, NaN], NaN); // true
893
+ * ```
894
+ * @since 0.5.0
895
+ */
896
+ declare function includes<T>(iterable: Iterable<T>, value: T): boolean;
897
+
578
898
  /**
579
899
  * Options of `range`.
580
900
  * @since 0.1.0
@@ -840,6 +1160,23 @@ declare function repeat_2<T>(value: T, count: number): Iterable<T>;
840
1160
  */
841
1161
  declare function skip<T>(iterable: Iterable<T>, count: number): Iterable<T>;
842
1162
 
1163
+ /**
1164
+ * Lazily skips the values while `predicate` returns `true`, then yields the first rejected value and all the rest.
1165
+ * After the first rejected value, `predicate` is not called again.
1166
+ * If `predicate` throws, the source is closed and the error propagates.
1167
+ * @operation `Transformation`
1168
+ * @param iterable - the source `Iterable`
1169
+ * @param predicate - called with each value and its index until it returns `false`
1170
+ * @returns a lazy, re-runnable `Iterable` of the values from the first rejected one
1171
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
1172
+ * @example
1173
+ * ```ts
1174
+ * Array.from(Functions.skipWhile([1, 2, 5, 3], v => v < 4)); // [5, 3]
1175
+ * ```
1176
+ * @since 0.5.0
1177
+ */
1178
+ declare function skipWhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T>;
1179
+
843
1180
  /**
844
1181
  * Tells whether `iterable` contains a value; reads one value, then closes the source.
845
1182
  * @operation `Action`
@@ -885,6 +1222,41 @@ declare function some<T>(iterable: Iterable<T>, predicate: Predicate<T> | undefi
885
1222
  */
886
1223
  declare function take<T>(iterable: Iterable<T>, count: number): Iterable<T>;
887
1224
 
1225
+ /**
1226
+ * Lazily yields the values while a type guard accepts them, narrowing their type, then closes the source.
1227
+ * The source is never read past the first rejected value, which is not yielded.
1228
+ * If `predicate` throws, the source is closed and the error propagates.
1229
+ * @operation `Transformation`
1230
+ * @param iterable - the source `Iterable`
1231
+ * @param predicate - a type guard called with each value and its index; the first `false` ends the iterable
1232
+ * @returns a lazy, re-runnable `Iterable` of the narrowed values before the first rejected one
1233
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
1234
+ * @example
1235
+ * ```ts
1236
+ * const values: (number | string)[] = [1, 2, 'three', 4];
1237
+ * Array.from(Functions.takeWhile(values, (v): v is number => typeof v === 'number')); // number[], [1, 2]
1238
+ * ```
1239
+ * @since 0.5.0
1240
+ */
1241
+ declare function takeWhile<T, S extends T>(iterable: Iterable<T>, predicate: (value: T, index: number) => value is S): Iterable<S>;
1242
+
1243
+ /**
1244
+ * Lazily yields the values while `predicate` returns `true`, then closes the source.
1245
+ * The source is never read past the first rejected value, which is not yielded, so `takeWhile` can end an infinite source.
1246
+ * If `predicate` throws, the source is closed and the error propagates.
1247
+ * @operation `Transformation`
1248
+ * @param iterable - the source `Iterable`
1249
+ * @param predicate - called with each value and its index; the first `false` ends the iterable
1250
+ * @returns a lazy, re-runnable `Iterable` of the values before the first rejected one
1251
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
1252
+ * @example
1253
+ * ```ts
1254
+ * Array.from(Functions.takeWhile([1, 2, 5, 3], v => v < 4)); // [1, 2]
1255
+ * ```
1256
+ * @since 0.5.0
1257
+ */
1258
+ declare function takeWhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Iterable<T>;
1259
+
888
1260
  /**
889
1261
  * Lazily calls `tapper` on each value as it flows through, without changing it.
890
1262
  * If `tapper` throws, the source is closed and the error propagates.