iterable-linq-utility 0.2.0 → 0.4.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
@@ -98,6 +98,24 @@ declare function empty_2<T>(): Iterable<T>;
98
98
  */
99
99
  export declare function extend<K extends Extract<keyof IIterableLinq<unknown>, string>>(name: K, implementation: ChainMethod): void;
100
100
 
101
+ /**
102
+ * Lazily keeps the values accepted by a type guard and narrows their type.
103
+ * If `predicate` throws, the source is closed and the error propagates.
104
+ * @operation `Transformation`
105
+ * @param iterable - the source `Iterable`
106
+ * @param predicate - a type guard called with each value and its index; return `true` to keep the value
107
+ * @returns a lazy, re-runnable `Iterable` of the narrowed values
108
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
109
+ * @example
110
+ * ```ts
111
+ * const values: (number | string)[] = [1, 'two', 3];
112
+ * const strings = Functions.filter(values, (v): v is string => typeof v === 'string');
113
+ * Array.from(strings); // string[], ['two']
114
+ * ```
115
+ * @since 0.4.0
116
+ */
117
+ declare function filter<T, S extends T>(iterable: Iterable<T>, predicate: (value: T, index: number) => value is S): Iterable<S>;
118
+
101
119
  /**
102
120
  * Lazily keeps only the values that satisfy `predicate`.
103
121
  * If `predicate` throws, the source is closed and the error propagates.
@@ -241,7 +259,9 @@ declare namespace Functions {
241
259
  range,
242
260
  reduce,
243
261
  repeat_2 as repeat,
262
+ skip,
244
263
  some,
264
+ take,
245
265
  tap,
246
266
  tapChain
247
267
  }
@@ -294,6 +314,21 @@ export declare interface IIterableLinqBase<T> {
294
314
  * @since 0.0.1
295
315
  */
296
316
  collectToArray(): T[];
317
+ /**
318
+ * Keeps the values accepted by a type guard and narrows their type.
319
+ * If `predicate` throws, the source is closed and the error propagates.
320
+ * @operation `Transformation`
321
+ * @param predicate - a type guard called with each value and its index; return `true` to keep the value
322
+ * @returns a new chain with the narrowed values
323
+ * @throws Error if `predicate` is not a function
324
+ * @example
325
+ * ```ts
326
+ * const values: (number | string)[] = [1, 'two', 3];
327
+ * IterableLinq.from(values).filter((v): v is string => typeof v === 'string').collectToArray(); // string[], ['two']
328
+ * ```
329
+ * @since 0.4.0
330
+ */
331
+ filter<S extends T>(predicate: (value: T, index: number) => value is S): IIterableLinq<S>;
297
332
  /**
298
333
  * Keeps only the values that satisfy `predicate`.
299
334
  * If `predicate` throws, the source is closed and the error propagates.
@@ -460,19 +495,57 @@ export declare interface IIterableLinqBase<T> {
460
495
  * @since 0.0.10
461
496
  */
462
497
  reduce<R>(neutralElement: R, reducer: Reducer<T, R>): R;
498
+ /**
499
+ * Lazily skips the first `count` values and yields the rest.
500
+ * @operation `Transformation`
501
+ * @param count - how many values to skip; must be a non-negative integer
502
+ * @returns a lazy, re-runnable chain of the remaining values
503
+ * @throws Error if `count` is negative, not an integer, `NaN` or `Infinity`
504
+ * @example
505
+ * ```ts
506
+ * IterableLinq.from([1, 2, 3, 4, 5]).skip(2).collectToArray(); // [3, 4, 5]
507
+ * ```
508
+ * @since 0.3.0
509
+ */
510
+ skip(count: number): IIterableLinq<T>;
511
+ /**
512
+ * Runs the chain until its first value, then stops and closes the source.
513
+ * @operation `Action`
514
+ * @returns `true` if the chain contains a value; `false` when it is empty
515
+ * @example
516
+ * ```ts
517
+ * IterableLinq.from([1, 2, 3]).some(); // true
518
+ * ```
519
+ * @since 0.3.0
520
+ */
521
+ some(): boolean;
463
522
  /**
464
523
  * Runs the chain until a value satisfies `predicate`, then stops and closes the source.
465
524
  * @operation `Action`
466
- * @param predicate - called with each value and its index
467
- * @returns `true` if at least one value satisfies `predicate`; `false` when the chain is empty
468
- * @throws Error if `predicate` is not a function
525
+ * @param predicate - called with each value and its index; `undefined` checks only whether a value exists
526
+ * @returns `true` if at least one value satisfies `predicate`; `false` otherwise
527
+ * @throws Error if a provided `predicate` is not a function
469
528
  * @example
470
529
  * ```ts
471
530
  * IterableLinq.from([1, 2, 3]).some(v => v > 2); // true
472
531
  * ```
473
532
  * @since 0.0.1
474
533
  */
475
- some(predicate: Predicate<T>): boolean;
534
+ some(predicate: Predicate<T> | undefined): boolean;
535
+ /**
536
+ * Yields the first `count` values, then closes the source.
537
+ * The source is never read past the `count`-th value, so `take` also ends an infinite chain.
538
+ * @operation `Transformation`
539
+ * @param count - how many values to yield; must be a non-negative integer
540
+ * @returns a new chain with at most `count` values
541
+ * @throws Error if `count` is negative, not an integer, `NaN` or `Infinity`
542
+ * @example
543
+ * ```ts
544
+ * IterableLinq.from([1, 2, 3, 4, 5]).take(3).collectToArray(); // [1, 2, 3]
545
+ * ```
546
+ * @since 0.3.0
547
+ */
548
+ take(count: number): IIterableLinq<T>;
476
549
  /**
477
550
  * Calls `tapper` on each value as it flows through the chain, without changing it.
478
551
  * If `tapper` throws, the source is closed and the error propagates.
@@ -515,11 +588,12 @@ export declare interface IIterableLinqBase<T> {
515
588
  * @example
516
589
  * ```ts
517
590
  * let evens: IIterableLinq<number> | undefined;
518
- * IterableLinq.fromRange(10)
591
+ * const evensByTen = IterableLinq.fromRange(10)
519
592
  * .filter(v => v % 2 === 0)
520
593
  * .tapChainCreation(chain => { evens = chain; return unit(); })
521
594
  * .map(v => v * 10);
522
595
  * evens?.collectToArray(); // [0, 2, 4, 6, 8]
596
+ * evensByTen.collectToArray(); // [0, 20, 40, 60, 80]
523
597
  * ```
524
598
  * @since 0.0.10
525
599
  */
@@ -785,20 +859,65 @@ export declare function repeat<T>(value: T, count: number): IIterableLinq<T>;
785
859
  */
786
860
  declare function repeat_2<T>(value: T, count: number): Iterable<T>;
787
861
 
862
+ /**
863
+ * Lazily skips the first `count` values and yields the rest.
864
+ * @operation `Transformation`
865
+ * @param iterable - the source `Iterable`
866
+ * @param count - how many values to skip; must be a non-negative integer
867
+ * @returns a lazy, re-runnable `Iterable` of the remaining values
868
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `count` is negative, not an integer, `NaN` or `Infinity`
869
+ * @example
870
+ * ```ts
871
+ * Array.from(Functions.skip([1, 2, 3, 4, 5], 2)); // [3, 4, 5]
872
+ * ```
873
+ * @since 0.3.0
874
+ */
875
+ declare function skip<T>(iterable: Iterable<T>, count: number): Iterable<T>;
876
+
877
+ /**
878
+ * Tells whether `iterable` contains a value; reads one value, then closes the source.
879
+ * @operation `Action`
880
+ * @param iterable - the source `Iterable`
881
+ * @returns `true` if `iterable` contains a value; `false` when it is empty
882
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
883
+ * @example
884
+ * ```ts
885
+ * Functions.some([1, 2, 3]); // true
886
+ * ```
887
+ * @since 0.3.0
888
+ */
889
+ declare function some<T>(iterable: Iterable<T>): boolean;
890
+
788
891
  /**
789
892
  * Tells whether at least one value satisfies `predicate`; stops and closes the source at the first match.
790
893
  * @operation `Action`
791
894
  * @param iterable - the source `Iterable`
792
- * @param predicate - called with each value and its index
793
- * @returns `true` if a value satisfies `predicate`; `false` when `iterable` is empty
794
- * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
895
+ * @param predicate - called with each value and its index; `undefined` checks only whether a value exists
896
+ * @returns `true` if a value satisfies `predicate`; `false` otherwise
897
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if a provided `predicate` is not a function
795
898
  * @example
796
899
  * ```ts
797
900
  * Functions.some([1, 2, 3], v => v > 2); // true
798
901
  * ```
799
902
  * @since 0.0.10
800
903
  */
801
- declare function some<T>(iterable: Iterable<T>, predicate: Predicate<T>): boolean;
904
+ declare function some<T>(iterable: Iterable<T>, predicate: Predicate<T> | undefined): boolean;
905
+
906
+ /**
907
+ * Lazily yields the first `count` values, then closes the source.
908
+ * The source is never read past the `count`-th value, so `take` also ends an infinite source.
909
+ * @operation `Transformation`
910
+ * @param iterable - the source `Iterable`
911
+ * @param count - how many values to yield; must be a non-negative integer
912
+ * @returns a lazy, re-runnable `Iterable` of at most `count` values
913
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `count` is negative, not an integer, `NaN` or `Infinity`
914
+ * @example
915
+ * ```ts
916
+ * Array.from(Functions.take([1, 2, 3, 4, 5], 3)); // [1, 2, 3]
917
+ * ```
918
+ * @since 0.3.0
919
+ */
920
+ declare function take<T>(iterable: Iterable<T>, count: number): Iterable<T>;
802
921
 
803
922
  /**
804
923
  * Lazily calls `tapper` on each value as it flows through, without changing it.
package/dist/index.d.ts CHANGED
@@ -98,6 +98,24 @@ declare function empty_2<T>(): Iterable<T>;
98
98
  */
99
99
  export declare function extend<K extends Extract<keyof IIterableLinq<unknown>, string>>(name: K, implementation: ChainMethod): void;
100
100
 
101
+ /**
102
+ * Lazily keeps the values accepted by a type guard and narrows their type.
103
+ * If `predicate` throws, the source is closed and the error propagates.
104
+ * @operation `Transformation`
105
+ * @param iterable - the source `Iterable`
106
+ * @param predicate - a type guard called with each value and its index; return `true` to keep the value
107
+ * @returns a lazy, re-runnable `Iterable` of the narrowed values
108
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
109
+ * @example
110
+ * ```ts
111
+ * const values: (number | string)[] = [1, 'two', 3];
112
+ * const strings = Functions.filter(values, (v): v is string => typeof v === 'string');
113
+ * Array.from(strings); // string[], ['two']
114
+ * ```
115
+ * @since 0.4.0
116
+ */
117
+ declare function filter<T, S extends T>(iterable: Iterable<T>, predicate: (value: T, index: number) => value is S): Iterable<S>;
118
+
101
119
  /**
102
120
  * Lazily keeps only the values that satisfy `predicate`.
103
121
  * If `predicate` throws, the source is closed and the error propagates.
@@ -241,7 +259,9 @@ declare namespace Functions {
241
259
  range,
242
260
  reduce,
243
261
  repeat_2 as repeat,
262
+ skip,
244
263
  some,
264
+ take,
245
265
  tap,
246
266
  tapChain
247
267
  }
@@ -294,6 +314,21 @@ export declare interface IIterableLinqBase<T> {
294
314
  * @since 0.0.1
295
315
  */
296
316
  collectToArray(): T[];
317
+ /**
318
+ * Keeps the values accepted by a type guard and narrows their type.
319
+ * If `predicate` throws, the source is closed and the error propagates.
320
+ * @operation `Transformation`
321
+ * @param predicate - a type guard called with each value and its index; return `true` to keep the value
322
+ * @returns a new chain with the narrowed values
323
+ * @throws Error if `predicate` is not a function
324
+ * @example
325
+ * ```ts
326
+ * const values: (number | string)[] = [1, 'two', 3];
327
+ * IterableLinq.from(values).filter((v): v is string => typeof v === 'string').collectToArray(); // string[], ['two']
328
+ * ```
329
+ * @since 0.4.0
330
+ */
331
+ filter<S extends T>(predicate: (value: T, index: number) => value is S): IIterableLinq<S>;
297
332
  /**
298
333
  * Keeps only the values that satisfy `predicate`.
299
334
  * If `predicate` throws, the source is closed and the error propagates.
@@ -460,19 +495,57 @@ export declare interface IIterableLinqBase<T> {
460
495
  * @since 0.0.10
461
496
  */
462
497
  reduce<R>(neutralElement: R, reducer: Reducer<T, R>): R;
498
+ /**
499
+ * Lazily skips the first `count` values and yields the rest.
500
+ * @operation `Transformation`
501
+ * @param count - how many values to skip; must be a non-negative integer
502
+ * @returns a lazy, re-runnable chain of the remaining values
503
+ * @throws Error if `count` is negative, not an integer, `NaN` or `Infinity`
504
+ * @example
505
+ * ```ts
506
+ * IterableLinq.from([1, 2, 3, 4, 5]).skip(2).collectToArray(); // [3, 4, 5]
507
+ * ```
508
+ * @since 0.3.0
509
+ */
510
+ skip(count: number): IIterableLinq<T>;
511
+ /**
512
+ * Runs the chain until its first value, then stops and closes the source.
513
+ * @operation `Action`
514
+ * @returns `true` if the chain contains a value; `false` when it is empty
515
+ * @example
516
+ * ```ts
517
+ * IterableLinq.from([1, 2, 3]).some(); // true
518
+ * ```
519
+ * @since 0.3.0
520
+ */
521
+ some(): boolean;
463
522
  /**
464
523
  * Runs the chain until a value satisfies `predicate`, then stops and closes the source.
465
524
  * @operation `Action`
466
- * @param predicate - called with each value and its index
467
- * @returns `true` if at least one value satisfies `predicate`; `false` when the chain is empty
468
- * @throws Error if `predicate` is not a function
525
+ * @param predicate - called with each value and its index; `undefined` checks only whether a value exists
526
+ * @returns `true` if at least one value satisfies `predicate`; `false` otherwise
527
+ * @throws Error if a provided `predicate` is not a function
469
528
  * @example
470
529
  * ```ts
471
530
  * IterableLinq.from([1, 2, 3]).some(v => v > 2); // true
472
531
  * ```
473
532
  * @since 0.0.1
474
533
  */
475
- some(predicate: Predicate<T>): boolean;
534
+ some(predicate: Predicate<T> | undefined): boolean;
535
+ /**
536
+ * Yields the first `count` values, then closes the source.
537
+ * The source is never read past the `count`-th value, so `take` also ends an infinite chain.
538
+ * @operation `Transformation`
539
+ * @param count - how many values to yield; must be a non-negative integer
540
+ * @returns a new chain with at most `count` values
541
+ * @throws Error if `count` is negative, not an integer, `NaN` or `Infinity`
542
+ * @example
543
+ * ```ts
544
+ * IterableLinq.from([1, 2, 3, 4, 5]).take(3).collectToArray(); // [1, 2, 3]
545
+ * ```
546
+ * @since 0.3.0
547
+ */
548
+ take(count: number): IIterableLinq<T>;
476
549
  /**
477
550
  * Calls `tapper` on each value as it flows through the chain, without changing it.
478
551
  * If `tapper` throws, the source is closed and the error propagates.
@@ -515,11 +588,12 @@ export declare interface IIterableLinqBase<T> {
515
588
  * @example
516
589
  * ```ts
517
590
  * let evens: IIterableLinq<number> | undefined;
518
- * IterableLinq.fromRange(10)
591
+ * const evensByTen = IterableLinq.fromRange(10)
519
592
  * .filter(v => v % 2 === 0)
520
593
  * .tapChainCreation(chain => { evens = chain; return unit(); })
521
594
  * .map(v => v * 10);
522
595
  * evens?.collectToArray(); // [0, 2, 4, 6, 8]
596
+ * evensByTen.collectToArray(); // [0, 20, 40, 60, 80]
523
597
  * ```
524
598
  * @since 0.0.10
525
599
  */
@@ -785,20 +859,65 @@ export declare function repeat<T>(value: T, count: number): IIterableLinq<T>;
785
859
  */
786
860
  declare function repeat_2<T>(value: T, count: number): Iterable<T>;
787
861
 
862
+ /**
863
+ * Lazily skips the first `count` values and yields the rest.
864
+ * @operation `Transformation`
865
+ * @param iterable - the source `Iterable`
866
+ * @param count - how many values to skip; must be a non-negative integer
867
+ * @returns a lazy, re-runnable `Iterable` of the remaining values
868
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `count` is negative, not an integer, `NaN` or `Infinity`
869
+ * @example
870
+ * ```ts
871
+ * Array.from(Functions.skip([1, 2, 3, 4, 5], 2)); // [3, 4, 5]
872
+ * ```
873
+ * @since 0.3.0
874
+ */
875
+ declare function skip<T>(iterable: Iterable<T>, count: number): Iterable<T>;
876
+
877
+ /**
878
+ * Tells whether `iterable` contains a value; reads one value, then closes the source.
879
+ * @operation `Action`
880
+ * @param iterable - the source `Iterable`
881
+ * @returns `true` if `iterable` contains a value; `false` when it is empty
882
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
883
+ * @example
884
+ * ```ts
885
+ * Functions.some([1, 2, 3]); // true
886
+ * ```
887
+ * @since 0.3.0
888
+ */
889
+ declare function some<T>(iterable: Iterable<T>): boolean;
890
+
788
891
  /**
789
892
  * Tells whether at least one value satisfies `predicate`; stops and closes the source at the first match.
790
893
  * @operation `Action`
791
894
  * @param iterable - the source `Iterable`
792
- * @param predicate - called with each value and its index
793
- * @returns `true` if a value satisfies `predicate`; `false` when `iterable` is empty
794
- * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `predicate` is not a function
895
+ * @param predicate - called with each value and its index; `undefined` checks only whether a value exists
896
+ * @returns `true` if a value satisfies `predicate`; `false` otherwise
897
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if a provided `predicate` is not a function
795
898
  * @example
796
899
  * ```ts
797
900
  * Functions.some([1, 2, 3], v => v > 2); // true
798
901
  * ```
799
902
  * @since 0.0.10
800
903
  */
801
- declare function some<T>(iterable: Iterable<T>, predicate: Predicate<T>): boolean;
904
+ declare function some<T>(iterable: Iterable<T>, predicate: Predicate<T> | undefined): boolean;
905
+
906
+ /**
907
+ * Lazily yields the first `count` values, then closes the source.
908
+ * The source is never read past the `count`-th value, so `take` also ends an infinite source.
909
+ * @operation `Transformation`
910
+ * @param iterable - the source `Iterable`
911
+ * @param count - how many values to yield; must be a non-negative integer
912
+ * @returns a lazy, re-runnable `Iterable` of at most `count` values
913
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `count` is negative, not an integer, `NaN` or `Infinity`
914
+ * @example
915
+ * ```ts
916
+ * Array.from(Functions.take([1, 2, 3, 4, 5], 3)); // [1, 2, 3]
917
+ * ```
918
+ * @since 0.3.0
919
+ */
920
+ declare function take<T>(iterable: Iterable<T>, count: number): Iterable<T>;
802
921
 
803
922
  /**
804
923
  * Lazily calls `tapper` on each value as it flows through, without changing it.
@@ -57,10 +57,10 @@ function c(e) {
57
57
  function l(e, t) {
58
58
  if (!n(e)) throw Error(`The "${t}" function must be provided`);
59
59
  }
60
- function ee(e, t) {
60
+ function u(e, t) {
61
61
  if (!Number.isInteger(e) || e < 0) throw Error(`The "${t}" parameter must be a non-negative integer`);
62
62
  }
63
- function u(e, t) {
63
+ function ee(e, t) {
64
64
  if (!Number.isFinite(e) || e === 0) throw Error(`The "${t}" parameter must be a finite number other than 0`);
65
65
  }
66
66
  function te(e, t) {
@@ -143,9 +143,9 @@ function _() {
143
143
  //#endregion
144
144
  //#region src/functions/filter.ts
145
145
  function v(e, t) {
146
- return c(e), l(t, "predicate"), new p(() => new y(e, t));
146
+ return c(e), l(t, "predicate"), new p(() => new re(e, t));
147
147
  }
148
- var y = class extends m {
148
+ var re = class extends m {
149
149
  predicate;
150
150
  constructor(e, t) {
151
151
  super(e), this.predicate = t;
@@ -165,10 +165,10 @@ var y = class extends m {
165
165
  };
166
166
  //#endregion
167
167
  //#region src/functions/flatMap.ts
168
- function b(e, t) {
169
- return c(e), l(t, "mapper"), new p(() => new re(e, t));
168
+ function y(e, t) {
169
+ return c(e), l(t, "mapper"), new p(() => new ie(e, t));
170
170
  }
171
- var re = class e extends m {
171
+ var ie = class e extends m {
172
172
  mapper;
173
173
  static steps = {
174
174
  outer: (t) => {
@@ -229,7 +229,7 @@ var re = class e extends m {
229
229
  throw e.inner = void 0, e.closeAfterCallbackError(), t;
230
230
  }
231
231
  }
232
- }, x = class e {
232
+ }, b = class e {
233
233
  static instance = e.createFrozen();
234
234
  constructor() {}
235
235
  static createFrozen() {
@@ -237,29 +237,29 @@ var re = class e extends m {
237
237
  return Object.freeze(t), t;
238
238
  }
239
239
  };
240
- function S() {
241
- return x.instance;
240
+ function x() {
241
+ return b.instance;
242
242
  }
243
243
  //#endregion
244
244
  //#region src/functions/forEach.ts
245
- function C(e, t) {
245
+ function S(e, t) {
246
246
  c(e), l(t, "action");
247
247
  let n = 0;
248
248
  for (let r of e) t(r, n++);
249
- return S();
249
+ return x();
250
250
  }
251
- async function w(e, t) {
251
+ async function C(e, t) {
252
252
  c(e), l(t, "action");
253
253
  let n = 0;
254
254
  for (let r of e) await t(r, n++);
255
- return S();
255
+ return x();
256
256
  }
257
257
  //#endregion
258
258
  //#region src/functions/map.ts
259
- function T(e, t) {
260
- return c(e), l(t, "mapper"), new p(() => new E(e, t));
259
+ function w(e, t) {
260
+ return c(e), l(t, "mapper"), new p(() => new ae(e, t));
261
261
  }
262
- var E = class extends m {
262
+ var ae = class extends m {
263
263
  mapper;
264
264
  constructor(e, t) {
265
265
  super(e), this.mapper = t;
@@ -278,18 +278,18 @@ var E = class extends m {
278
278
  };
279
279
  //#endregion
280
280
  //#region src/collections/linkedList.ts
281
- function D(e) {
281
+ function T(e) {
282
282
  c(e);
283
- let t = new ie();
283
+ let t = new oe();
284
284
  for (let n of e) t.addLast(n);
285
285
  return t;
286
286
  }
287
- var ie = class {
287
+ var oe = class {
288
288
  internalSize = 0;
289
289
  head = null;
290
290
  tail = null;
291
291
  [Symbol.iterator]() {
292
- return new ae(this.head);
292
+ return new se(this.head);
293
293
  }
294
294
  addFirst(e) {
295
295
  let t = {
@@ -308,7 +308,7 @@ var ie = class {
308
308
  size() {
309
309
  return this.internalSize;
310
310
  }
311
- }, ae = class extends f {
311
+ }, se = class extends f {
312
312
  current;
313
313
  constructor(e) {
314
314
  super(), this.current = e;
@@ -320,13 +320,13 @@ var ie = class {
320
320
  };
321
321
  //#endregion
322
322
  //#region src/functions/materialize.ts
323
- function O(e) {
324
- return c(e), e instanceof k ? e : new k(e);
323
+ function E(e) {
324
+ return c(e), e instanceof D ? e : new D(e);
325
325
  }
326
- var k = class {
326
+ var D = class {
327
327
  source;
328
328
  constructor(e) {
329
- this.source = D(e);
329
+ this.source = T(e);
330
330
  }
331
331
  [Symbol.iterator]() {
332
332
  return this.source[Symbol.iterator]();
@@ -334,29 +334,29 @@ var k = class {
334
334
  };
335
335
  //#endregion
336
336
  //#region src/functions/max.ts
337
- function A(e, t) {
337
+ function O(e, t) {
338
338
  return c(e), a(e, i(t), 1);
339
339
  }
340
340
  //#endregion
341
341
  //#region src/functions/memoize.ts
342
- function j() {
342
+ function k() {
343
343
  return { allowPartialMemoization: !0 };
344
344
  }
345
- function M(e, t) {
345
+ function A(e, t) {
346
346
  c(e);
347
347
  let n = {
348
- ...j(),
348
+ ...k(),
349
349
  ...t
350
350
  }.allowPartialMemoization;
351
- return e instanceof F ? n ? e.changePartialMemoizationBehaviour() : e : e instanceof I ? n ? e : e.changePartialMemoizationBehaviour() : n ? new I(e) : new F(e);
351
+ return e instanceof N ? n ? e.changePartialMemoizationBehaviour() : e : e instanceof P ? n ? e : e.changePartialMemoizationBehaviour() : n ? new P(e) : new N(e);
352
352
  }
353
- function N() {
353
+ function j() {
354
354
  return {
355
355
  values: [],
356
356
  finished: !1
357
357
  };
358
358
  }
359
- function P(e, t) {
359
+ function M(e, t) {
360
360
  if (t.error) throw t.error.value;
361
361
  if (t.finished) return !1;
362
362
  t.source ??= e[Symbol.iterator]();
@@ -368,31 +368,31 @@ function P(e, t) {
368
368
  }
369
369
  return n.done === !0 ? (t.finished = !0, t.source = void 0, !1) : (t.values.push(n.value), !0);
370
370
  }
371
- var F = class {
371
+ var N = class {
372
372
  source;
373
- cache = N();
373
+ cache = j();
374
374
  constructor(e) {
375
375
  this.source = e;
376
376
  }
377
377
  [Symbol.iterator]() {
378
- return new L(this.source, this.cache, !0);
378
+ return new F(this.source, this.cache, !0);
379
379
  }
380
380
  changePartialMemoizationBehaviour() {
381
- return new I(this.source);
381
+ return new P(this.source);
382
382
  }
383
- }, I = class {
383
+ }, P = class {
384
384
  source;
385
- cache = N();
385
+ cache = j();
386
386
  constructor(e) {
387
387
  this.source = e;
388
388
  }
389
389
  [Symbol.iterator]() {
390
- return new L(this.source, this.cache, !1);
390
+ return new F(this.source, this.cache, !1);
391
391
  }
392
392
  changePartialMemoizationBehaviour() {
393
- return new F(this.source);
393
+ return new N(this.source);
394
394
  }
395
- }, L = class extends f {
395
+ }, F = class extends f {
396
396
  source;
397
397
  cache;
398
398
  drainFirst;
@@ -401,28 +401,28 @@ var F = class {
401
401
  super(), this.source = e, this.cache = t, this.drainFirst = n;
402
402
  }
403
403
  advance() {
404
- if (this.drainFirst) for (; P(this.source, this.cache););
405
- return this.index < this.cache.values.length || P(this.source, this.cache) ? o(this.cache.values[this.index++]) : s();
404
+ if (this.drainFirst) for (; M(this.source, this.cache););
405
+ return this.index < this.cache.values.length || M(this.source, this.cache) ? o(this.cache.values[this.index++]) : s();
406
406
  }
407
407
  };
408
408
  //#endregion
409
409
  //#region src/functions/min.ts
410
- function R(e, t) {
410
+ function I(e, t) {
411
411
  return c(e), a(e, i(t), -1);
412
412
  }
413
413
  //#endregion
414
414
  //#region src/functions/range.ts
415
- function z(e, t, n) {
415
+ function L(e, t, n) {
416
416
  let r = typeof t == "number", i = r ? e : 0, a = r ? t : e;
417
417
  if (!r && n !== void 0) throw Error("The \"options\" parameter must be the second argument when \"start\" is omitted");
418
418
  let o = r ? n : t;
419
419
  o !== void 0 && te(o, "options");
420
420
  let { step: s = 1, reverse: c = !1 } = o ?? {};
421
- u(s, "step");
422
- let l = oe(i, a, Math.abs(s), c);
423
- return l.length > 0 ? new p(() => new se(l.first, l.step, l.length)) : _();
421
+ ee(s, "step");
422
+ let l = ce(i, a, Math.abs(s), c);
423
+ return l.length > 0 ? new p(() => new le(l.first, l.step, l.length)) : _();
424
424
  }
425
- function oe(e, t, n, r) {
425
+ function ce(e, t, n, r) {
426
426
  let i = t < e ? -n : n, a = Math.ceil(Math.abs(t - e) / n);
427
427
  return r ? {
428
428
  first: e + (a - 1) * i,
@@ -434,7 +434,7 @@ function oe(e, t, n, r) {
434
434
  length: a
435
435
  };
436
436
  }
437
- var se = class extends f {
437
+ var le = class extends f {
438
438
  first;
439
439
  step;
440
440
  length;
@@ -448,15 +448,15 @@ var se = class extends f {
448
448
  };
449
449
  //#endregion
450
450
  //#region src/functions/reduce.ts
451
- function B(e, ...t) {
452
- if (c(e), t.length === 1) return V(e, t[0]);
451
+ function R(e, ...t) {
452
+ if (c(e), t.length === 1) return z(e, t[0]);
453
453
  let [n, r] = t;
454
454
  l(r, "reducer");
455
455
  let i = n, a = 0;
456
456
  for (let t of e) i = r(i, t, a++);
457
457
  return i;
458
458
  }
459
- function V(e, t) {
459
+ function z(e, t) {
460
460
  l(t, "reducer");
461
461
  let n, r = 0;
462
462
  for (let i of e) n = r === 0 ? i : t(n, i, r), r++;
@@ -465,23 +465,62 @@ function V(e, t) {
465
465
  }
466
466
  //#endregion
467
467
  //#region src/functions/repeat.ts
468
- function H(e, t) {
469
- return ee(t, "count"), h(t, (t) => t > 0 ? [e, t - 1] : void 0);
468
+ function B(e, t) {
469
+ return u(t, "count"), h(t, (t) => t > 0 ? [e, t - 1] : void 0);
470
470
  }
471
471
  //#endregion
472
+ //#region src/functions/skip.ts
473
+ function V(e, t) {
474
+ return c(e), u(t, "count"), new p(() => new H(e, t));
475
+ }
476
+ var H = class extends m {
477
+ count;
478
+ constructor(e, t) {
479
+ super(e), this.count = t;
480
+ }
481
+ advance() {
482
+ for (; this.index < this.count;) {
483
+ let e = this.source.next();
484
+ if (e.done === !0) return e;
485
+ this.index++;
486
+ }
487
+ return this.source.next();
488
+ }
489
+ };
490
+ //#endregion
472
491
  //#region src/functions/some.ts
473
492
  function U(e, t) {
474
- c(e), l(t, "predicate");
493
+ if (c(e), t === void 0) {
494
+ for (let t of e) return !0;
495
+ return !1;
496
+ }
497
+ l(t, "predicate");
475
498
  let n = 0;
476
499
  for (let r of e) if (t(r, n++)) return !0;
477
500
  return !1;
478
501
  }
479
502
  //#endregion
480
- //#region src/functions/tap.ts
503
+ //#region src/functions/take.ts
481
504
  function W(e, t) {
482
- return c(e), l(t, "tapper"), new p(() => new G(e, t));
505
+ return c(e), u(t, "count"), new p(() => new ue(e, t));
506
+ }
507
+ var ue = class extends m {
508
+ count;
509
+ constructor(e, t) {
510
+ super(e), this.count = t;
511
+ }
512
+ advance() {
513
+ if (this.index >= this.count) return this.source.return?.(), s();
514
+ let e = this.source.next();
515
+ return e.done === !0 ? e : (this.index++, o(e.value));
516
+ }
517
+ };
518
+ //#endregion
519
+ //#region src/functions/tap.ts
520
+ function G(e, t) {
521
+ return c(e), l(t, "tapper"), new p(() => new de(e, t));
483
522
  }
484
- var G = class extends m {
523
+ var de = class extends m {
485
524
  tapper;
486
525
  constructor(e, t) {
487
526
  super(e), this.tapper = t;
@@ -504,24 +543,26 @@ function K(e, t) {
504
543
  }
505
544
  //#endregion
506
545
  //#region src/functions/index.ts
507
- var ce = /* @__PURE__ */ t({
546
+ var fe = /* @__PURE__ */ t({
508
547
  collectToArray: () => d,
509
548
  empty: () => _,
510
549
  filter: () => v,
511
- flatMap: () => b,
512
- forEach: () => C,
513
- forEachAsync: () => w,
514
- getMemoizeDefaultOptions: () => j,
515
- map: () => T,
516
- materialize: () => O,
517
- max: () => A,
518
- memoize: () => M,
519
- min: () => R,
520
- range: () => z,
521
- reduce: () => B,
522
- repeat: () => H,
550
+ flatMap: () => y,
551
+ forEach: () => S,
552
+ forEachAsync: () => C,
553
+ getMemoizeDefaultOptions: () => k,
554
+ map: () => w,
555
+ materialize: () => E,
556
+ max: () => O,
557
+ memoize: () => A,
558
+ min: () => I,
559
+ range: () => L,
560
+ reduce: () => R,
561
+ repeat: () => B,
562
+ skip: () => V,
523
563
  some: () => U,
524
- tap: () => W,
564
+ take: () => W,
565
+ tap: () => G,
525
566
  tapChain: () => K
526
567
  }), q = Symbol.for("iterable-linq-utility.IIterableLinq");
527
568
  //#endregion
@@ -544,38 +585,44 @@ var Y = class {
544
585
  return J(v(this.iterable, e));
545
586
  }
546
587
  flatMap(e) {
547
- return J(b(this.iterable, e));
588
+ return J(y(this.iterable, e));
548
589
  }
549
590
  forEach(e) {
550
- return C(this.iterable, e);
591
+ return S(this.iterable, e);
551
592
  }
552
593
  forEachAsync(e) {
553
- return w(this.iterable, e);
594
+ return C(this.iterable, e);
554
595
  }
555
596
  map(e) {
556
- return J(T(this.iterable, e));
597
+ return J(w(this.iterable, e));
557
598
  }
558
599
  materialize() {
559
- return J(O(this.iterable));
600
+ return J(E(this.iterable));
560
601
  }
561
602
  max(e) {
562
- return A(this.iterable, e);
603
+ return O(this.iterable, e);
563
604
  }
564
605
  memoize(e) {
565
- return J(M(this.iterable, e));
606
+ return J(A(this.iterable, e));
566
607
  }
567
608
  min(e) {
568
- return R(this.iterable, e);
609
+ return I(this.iterable, e);
569
610
  }
570
611
  reduce(...e) {
571
- return e.length === 1 ? B(this.iterable, e[0]) : B(this.iterable, e[0], e[1]);
612
+ return e.length === 1 ? R(this.iterable, e[0]) : R(this.iterable, e[0], e[1]);
613
+ }
614
+ skip(e) {
615
+ return J(V(this.iterable, e));
572
616
  }
573
617
  some(e) {
574
618
  return U(this.iterable, e);
575
619
  }
576
- tap(e) {
620
+ take(e) {
577
621
  return J(W(this.iterable, e));
578
622
  }
623
+ tap(e) {
624
+ return J(G(this.iterable, e));
625
+ }
579
626
  tapChain(e) {
580
627
  return J(K(this.iterable, e));
581
628
  }
@@ -596,7 +643,7 @@ Object.defineProperty(Y.prototype, q, {
596
643
  function X() {
597
644
  return Y.prototype;
598
645
  }
599
- function le(e) {
646
+ function pe(e) {
600
647
  return typeof e == "object" && !!e && e[q] === !0;
601
648
  }
602
649
  function Z(e, t) {
@@ -611,11 +658,11 @@ function Z(e, t) {
611
658
  function Q(e, t) {
612
659
  ne(e, "name"), l(t, "implementation");
613
660
  }
614
- function ue(e, t) {
661
+ function me(e, t) {
615
662
  if (Q(e, t), e in J([])) throw Error(`"${e}" already exists on IIterableLinq: use override() to replace it`);
616
663
  Z(e, t);
617
664
  }
618
- function de(e, t) {
665
+ function he(e, t) {
619
666
  Q(e, t);
620
667
  let n = e;
621
668
  if (!(n !== "constructor" && Object.prototype.hasOwnProperty.call(X(), n))) throw Error(`"${n}" is not a method of IIterableLinq: use extend() to add it`);
@@ -623,19 +670,19 @@ function de(e, t) {
623
670
  }
624
671
  //#endregion
625
672
  //#region src/index.ts
626
- function fe() {
673
+ function ge() {
627
674
  return $(_());
628
675
  }
629
676
  function $(e) {
630
677
  return c(e), J(e);
631
678
  }
632
- function pe(e, t, n) {
633
- if (typeof t == "number") return $(z(e, t, n));
679
+ function _e(e, t, n) {
680
+ if (typeof t == "number") return $(L(e, t, n));
634
681
  if (n !== void 0) throw Error("The \"options\" parameter must be the second argument when \"start\" is omitted");
635
- return $(z(e, t));
682
+ return $(L(e, t));
636
683
  }
637
- function me(e, t) {
638
- return $(H(e, t));
684
+ function ve(e, t) {
685
+ return $(B(e, t));
639
686
  }
640
687
  //#endregion
641
- export { ce as Functions, x as Unit, fe as empty, ue as extend, $ as from, pe as fromRange, le as isIterableLinq, de as override, me as repeat, S as unit };
688
+ export { fe as Functions, b as Unit, ge as empty, me as extend, $ as from, _e as fromRange, pe as isIterableLinq, he as override, ve as repeat, x as unit };
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.IterableLinq={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r};function r(e){return typeof e==`function`}function i(e,t){return e<t?-1:e===t?0:1}function a(e){if(e==null)return i;if(r(e))return e;let t=Array.isArray(e)?e:[e];return(e,n)=>{for(let r of t){let t=i(e[r],n[r]);if(t!==0)return t}return 0}}function o(e,t,n){let r,i=!1;for(let a of e)!i||r==null&&a!=null?(r=a,i=!0):a!=null&&n*t(r,a)<0&&(r=a);return r}function s(e){return{done:!1,value:e}}function c(e){return{done:!0,value:e}}function l(e){if(e==null)throw Error(`The "sourceIterable" must be provided`);if(!r(e[Symbol.iterator]))throw Error(`The provided "sourceIterable" does not conform to the iterator protocol https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol. It must implement the "[Symbol.iterator]" function.`)}function u(e,t){if(!r(e))throw Error(`The "${t}" function must be provided`)}function d(e,t){if(!Number.isInteger(e)||e<0)throw Error(`The "${t}" parameter must be a non-negative integer`)}function ee(e,t){if(!Number.isFinite(e)||e===0)throw Error(`The "${t}" parameter must be a finite number other than 0`)}function te(e,t){if(typeof e!=`object`||!e)throw Error(`The "${t}" parameter must be an object`)}function ne(e,t){if(typeof e!=`string`||e.length===0)throw Error(`The "${t}" parameter must be a non-empty string`)}function f(e){if(l(e),Array.isArray(e)||e instanceof Set)return Array.from(e);let t=[];for(let n of e)t.push(n);return t}var p=class{done=!1;next(){if(this.done)return c();let e=this.advance();return e.done===!0&&(this.done=!0),e}return(e){return this.done||(this.done=!0,this.onReturn(e)),c(e)}[Symbol.iterator](){return this}onReturn(e){}closeAfterCallbackError(){if(!this.done){this.done=!0;try{this.onReturn()}catch{}}}},m=class{createIterator;constructor(e){this.createIterator=e}[Symbol.iterator](){return this.createIterator()}},h=class extends p{source;index=0;constructor(e){super(),this.source=e[Symbol.iterator]()}onReturn(e){this.source.return?.(e)}};function g(e,t){return new m(()=>new re(e,t))}var re=class extends p{state;step;constructor(e,t){super(),this.state=e,this.step=t}advance(){let e=this.step(this.state);return e===void 0?c():(this.state=e[1],s(e[0]))}};function _(){return g(void 0,()=>void 0)}function v(e,t){return l(e),u(t,`predicate`),new m(()=>new ie(e,t))}var ie=class extends h{predicate;constructor(e,t){super(e),this.predicate=t}advance(){for(let e=this.source.next();;e=this.source.next()){if(e.done===!0)return e;let t;try{t=this.predicate(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}if(t)return e}}};function y(e,t){return l(e),u(t,`mapper`),new m(()=>new ae(e,t))}var ae=class e extends h{mapper;static steps={outer:t=>{let n=t.source.next();if(n.done===!0)return n;let r=e.mapNext(t,n.value);if(r===void 0){t.state=`inner`;return}if(r.length!==0)return t.array=r,t.position=1,t.state=`array`,s(r[0])},inner:t=>{let n=e.nextInner(t);if(n.done!==!0)return n;t.inner=void 0,t.state=`outer`},array:e=>{if(e.position<e.array.length)return s(e.array[e.position++]);e.array=void 0,e.state=`outer`}};state=`outer`;inner;array;position=0;constructor(e,t){super(e),this.mapper=t}advance(){for(;;){let t=e.steps[this.state](this);if(t!==void 0)return t}}onReturn(e){this.array=void 0;try{this.inner?.return?.(e)}finally{super.onReturn(e)}}static mapNext(e,t){try{let n=e.mapper(t,e.index++);if(Array.isArray(n))return n;e.inner=n[Symbol.iterator]();return}catch(t){throw e.closeAfterCallbackError(),t}}static nextInner(e){try{return e.inner.next()}catch(t){throw e.inner=void 0,e.closeAfterCallbackError(),t}}},b=class e{static instance=e.createFrozen();constructor(){}static createFrozen(){let t=new e;return Object.freeze(t),t}};function x(){return b.instance}function S(e,t){l(e),u(t,`action`);let n=0;for(let r of e)t(r,n++);return x()}async function C(e,t){l(e),u(t,`action`);let n=0;for(let r of e)await t(r,n++);return x()}function w(e,t){return l(e),u(t,`mapper`),new m(()=>new T(e,t))}var T=class extends h{mapper;constructor(e,t){super(e),this.mapper=t}advance(){let e=this.source.next();if(e.done===!0)return e;let t;try{t=this.mapper(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return s(t)}};function E(e){l(e);let t=new D;for(let n of e)t.addLast(n);return t}var D=class{internalSize=0;head=null;tail=null;[Symbol.iterator](){return new oe(this.head)}addFirst(e){let t={data:e,nextNode:this.head};return this.tail===null&&(this.tail=t),this.head=t,this.internalSize++,this}addLast(e){let t={data:e,nextNode:null};return this.tail===null?this.head=t:this.tail.nextNode=t,this.tail=t,this.internalSize++,this}size(){return this.internalSize}},oe=class extends p{current;constructor(e){super(),this.current=e}advance(){let e=this.current;return e===null?c():(this.current=e.nextNode,s(e.data))}};function O(e){return l(e),e instanceof k?e:new k(e)}var k=class{source;constructor(e){this.source=E(e)}[Symbol.iterator](){return this.source[Symbol.iterator]()}};function A(e,t){return l(e),o(e,a(t),1)}function j(){return{allowPartialMemoization:!0}}function M(e,t){l(e);let n={...j(),...t}.allowPartialMemoization;return e instanceof F?n?e.changePartialMemoizationBehaviour():e:e instanceof I?n?e:e.changePartialMemoizationBehaviour():n?new I(e):new F(e)}function N(){return{values:[],finished:!1}}function P(e,t){if(t.error)throw t.error.value;if(t.finished)return!1;t.source??=e[Symbol.iterator]();let n;try{n=t.source.next()}catch(e){throw t.error={value:e},t.source=void 0,e}return n.done===!0?(t.finished=!0,t.source=void 0,!1):(t.values.push(n.value),!0)}var F=class{source;cache=N();constructor(e){this.source=e}[Symbol.iterator](){return new L(this.source,this.cache,!0)}changePartialMemoizationBehaviour(){return new I(this.source)}},I=class{source;cache=N();constructor(e){this.source=e}[Symbol.iterator](){return new L(this.source,this.cache,!1)}changePartialMemoizationBehaviour(){return new F(this.source)}},L=class extends p{source;cache;drainFirst;index=0;constructor(e,t,n){super(),this.source=e,this.cache=t,this.drainFirst=n}advance(){if(this.drainFirst)for(;P(this.source,this.cache););return this.index<this.cache.values.length||P(this.source,this.cache)?s(this.cache.values[this.index++]):c()}};function R(e,t){return l(e),o(e,a(t),-1)}function z(e,t,n){let r=typeof t==`number`,i=r?e:0,a=r?t:e;if(!r&&n!==void 0)throw Error(`The "options" parameter must be the second argument when "start" is omitted`);let o=r?n:t;o!==void 0&&te(o,`options`);let{step:s=1,reverse:c=!1}=o??{};ee(s,`step`);let l=se(i,a,Math.abs(s),c);return l.length>0?new m(()=>new B(l.first,l.step,l.length)):_()}function se(e,t,n,r){let i=t<e?-n:n,a=Math.ceil(Math.abs(t-e)/n);return r?{first:e+(a-1)*i,step:-i,length:a}:{first:e,step:i,length:a}}var B=class extends p{first;step;length;index=0;constructor(e,t,n){super(),this.first=e,this.step=t,this.length=n}advance(){return this.index>=this.length?c():s(this.first+this.index++*this.step)}};function V(e,...t){if(l(e),t.length===1)return H(e,t[0]);let[n,r]=t;u(r,`reducer`);let i=n,a=0;for(let t of e)i=r(i,t,a++);return i}function H(e,t){u(t,`reducer`);let n,r=0;for(let i of e)n=r===0?i:t(n,i,r),r++;if(r===0)throw Error(`The "sourceIterable" must not be empty when "reduce" has no seed`);return n}function U(e,t){return d(t,`count`),g(t,t=>t>0?[e,t-1]:void 0)}function W(e,t){l(e),u(t,`predicate`);let n=0;for(let r of e)if(t(r,n++))return!0;return!1}function G(e,t){return l(e),u(t,`tapper`),new m(()=>new ce(e,t))}var ce=class extends h{tapper;constructor(e,t){super(e),this.tapper=t}advance(){let e=this.source.next();if(e.done===!0)return e;try{this.tapper(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return e}};function K(e,t){return l(e),u(t,`tapper`),new m(()=>(t(e,0),e[Symbol.iterator]()))}var le=n({collectToArray:()=>f,empty:()=>_,filter:()=>v,flatMap:()=>y,forEach:()=>S,forEachAsync:()=>C,getMemoizeDefaultOptions:()=>j,map:()=>w,materialize:()=>O,max:()=>A,memoize:()=>M,min:()=>R,range:()=>z,reduce:()=>V,repeat:()=>U,some:()=>W,tap:()=>G,tapChain:()=>K}),q=Symbol.for(`iterable-linq-utility.IIterableLinq`);function J(e){return new Y(e)}var Y=class{iterable;constructor(e){this.iterable=e}[Symbol.iterator](){return this.iterable[Symbol.iterator]()}collectToArray(){return f(this.iterable)}filter(e){return J(v(this.iterable,e))}flatMap(e){return J(y(this.iterable,e))}forEach(e){return S(this.iterable,e)}forEachAsync(e){return C(this.iterable,e)}map(e){return J(w(this.iterable,e))}materialize(){return J(O(this.iterable))}max(e){return A(this.iterable,e)}memoize(e){return J(M(this.iterable,e))}min(e){return R(this.iterable,e)}reduce(...e){return e.length===1?V(this.iterable,e[0]):V(this.iterable,e[0],e[1])}some(e){return W(this.iterable,e)}tap(e){return J(G(this.iterable,e))}tapChain(e){return J(K(this.iterable,e))}tapChainCreation(e){u(e,`chainCreationTapper`);let t=this;return e(t),t}};Object.defineProperty(Y.prototype,q,{value:!0,enumerable:!1,writable:!1,configurable:!1});function X(){return Y.prototype}function ue(e){return typeof e==`object`&&!!e&&e[q]===!0}function Z(e,t){let n=Object.getOwnPropertyDescriptor(X(),e);Object.defineProperty(X(),e,{value:t,enumerable:!1,writable:n?.writable??!1,configurable:!0})}function Q(e,t){ne(e,`name`),u(t,`implementation`)}function de(e,t){if(Q(e,t),e in J([]))throw Error(`"${e}" already exists on IIterableLinq: use override() to replace it`);Z(e,t)}function fe(e,t){Q(e,t);let n=e;if(!(n!==`constructor`&&Object.prototype.hasOwnProperty.call(X(),n)))throw Error(`"${n}" is not a method of IIterableLinq: use extend() to add it`);Z(n,t)}function pe(){return $(_())}function $(e){return l(e),J(e)}function me(e,t,n){if(typeof t==`number`)return $(z(e,t,n));if(n!==void 0)throw Error(`The "options" parameter must be the second argument when "start" is omitted`);return $(z(e,t))}function he(e,t){return $(U(e,t))}Object.defineProperty(e,"Functions",{enumerable:!0,get:function(){return le}}),e.Unit=b,e.empty=pe,e.extend=de,e.from=$,e.fromRange=me,e.isIterableLinq=ue,e.override=fe,e.repeat=he,e.unit=x});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.IterableLinq={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r};function r(e){return typeof e==`function`}function i(e,t){return e<t?-1:e===t?0:1}function a(e){if(e==null)return i;if(r(e))return e;let t=Array.isArray(e)?e:[e];return(e,n)=>{for(let r of t){let t=i(e[r],n[r]);if(t!==0)return t}return 0}}function o(e,t,n){let r,i=!1;for(let a of e)!i||r==null&&a!=null?(r=a,i=!0):a!=null&&n*t(r,a)<0&&(r=a);return r}function s(e){return{done:!1,value:e}}function c(e){return{done:!0,value:e}}function l(e){if(e==null)throw Error(`The "sourceIterable" must be provided`);if(!r(e[Symbol.iterator]))throw Error(`The provided "sourceIterable" does not conform to the iterator protocol https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol. It must implement the "[Symbol.iterator]" function.`)}function u(e,t){if(!r(e))throw Error(`The "${t}" function must be provided`)}function d(e,t){if(!Number.isInteger(e)||e<0)throw Error(`The "${t}" parameter must be a non-negative integer`)}function f(e,t){if(!Number.isFinite(e)||e===0)throw Error(`The "${t}" parameter must be a finite number other than 0`)}function ee(e,t){if(typeof e!=`object`||!e)throw Error(`The "${t}" parameter must be an object`)}function te(e,t){if(typeof e!=`string`||e.length===0)throw Error(`The "${t}" parameter must be a non-empty string`)}function p(e){if(l(e),Array.isArray(e)||e instanceof Set)return Array.from(e);let t=[];for(let n of e)t.push(n);return t}var m=class{done=!1;next(){if(this.done)return c();let e=this.advance();return e.done===!0&&(this.done=!0),e}return(e){return this.done||(this.done=!0,this.onReturn(e)),c(e)}[Symbol.iterator](){return this}onReturn(e){}closeAfterCallbackError(){if(!this.done){this.done=!0;try{this.onReturn()}catch{}}}},h=class{createIterator;constructor(e){this.createIterator=e}[Symbol.iterator](){return this.createIterator()}},g=class extends m{source;index=0;constructor(e){super(),this.source=e[Symbol.iterator]()}onReturn(e){this.source.return?.(e)}};function _(e,t){return new h(()=>new ne(e,t))}var ne=class extends m{state;step;constructor(e,t){super(),this.state=e,this.step=t}advance(){let e=this.step(this.state);return e===void 0?c():(this.state=e[1],s(e[0]))}};function v(){return _(void 0,()=>void 0)}function y(e,t){return l(e),u(t,`predicate`),new h(()=>new re(e,t))}var re=class extends g{predicate;constructor(e,t){super(e),this.predicate=t}advance(){for(let e=this.source.next();;e=this.source.next()){if(e.done===!0)return e;let t;try{t=this.predicate(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}if(t)return e}}};function b(e,t){return l(e),u(t,`mapper`),new h(()=>new ie(e,t))}var ie=class e extends g{mapper;static steps={outer:t=>{let n=t.source.next();if(n.done===!0)return n;let r=e.mapNext(t,n.value);if(r===void 0){t.state=`inner`;return}if(r.length!==0)return t.array=r,t.position=1,t.state=`array`,s(r[0])},inner:t=>{let n=e.nextInner(t);if(n.done!==!0)return n;t.inner=void 0,t.state=`outer`},array:e=>{if(e.position<e.array.length)return s(e.array[e.position++]);e.array=void 0,e.state=`outer`}};state=`outer`;inner;array;position=0;constructor(e,t){super(e),this.mapper=t}advance(){for(;;){let t=e.steps[this.state](this);if(t!==void 0)return t}}onReturn(e){this.array=void 0;try{this.inner?.return?.(e)}finally{super.onReturn(e)}}static mapNext(e,t){try{let n=e.mapper(t,e.index++);if(Array.isArray(n))return n;e.inner=n[Symbol.iterator]();return}catch(t){throw e.closeAfterCallbackError(),t}}static nextInner(e){try{return e.inner.next()}catch(t){throw e.inner=void 0,e.closeAfterCallbackError(),t}}},x=class e{static instance=e.createFrozen();constructor(){}static createFrozen(){let t=new e;return Object.freeze(t),t}};function S(){return x.instance}function C(e,t){l(e),u(t,`action`);let n=0;for(let r of e)t(r,n++);return S()}async function w(e,t){l(e),u(t,`action`);let n=0;for(let r of e)await t(r,n++);return S()}function T(e,t){return l(e),u(t,`mapper`),new h(()=>new ae(e,t))}var ae=class extends g{mapper;constructor(e,t){super(e),this.mapper=t}advance(){let e=this.source.next();if(e.done===!0)return e;let t;try{t=this.mapper(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return s(t)}};function oe(e){l(e);let t=new se;for(let n of e)t.addLast(n);return t}var se=class{internalSize=0;head=null;tail=null;[Symbol.iterator](){return new ce(this.head)}addFirst(e){let t={data:e,nextNode:this.head};return this.tail===null&&(this.tail=t),this.head=t,this.internalSize++,this}addLast(e){let t={data:e,nextNode:null};return this.tail===null?this.head=t:this.tail.nextNode=t,this.tail=t,this.internalSize++,this}size(){return this.internalSize}},ce=class extends m{current;constructor(e){super(),this.current=e}advance(){let e=this.current;return e===null?c():(this.current=e.nextNode,s(e.data))}};function E(e){return l(e),e instanceof D?e:new D(e)}var D=class{source;constructor(e){this.source=oe(e)}[Symbol.iterator](){return this.source[Symbol.iterator]()}};function O(e,t){return l(e),o(e,a(t),1)}function k(){return{allowPartialMemoization:!0}}function A(e,t){l(e);let n={...k(),...t}.allowPartialMemoization;return e instanceof N?n?e.changePartialMemoizationBehaviour():e:e instanceof P?n?e:e.changePartialMemoizationBehaviour():n?new P(e):new N(e)}function j(){return{values:[],finished:!1}}function M(e,t){if(t.error)throw t.error.value;if(t.finished)return!1;t.source??=e[Symbol.iterator]();let n;try{n=t.source.next()}catch(e){throw t.error={value:e},t.source=void 0,e}return n.done===!0?(t.finished=!0,t.source=void 0,!1):(t.values.push(n.value),!0)}var N=class{source;cache=j();constructor(e){this.source=e}[Symbol.iterator](){return new F(this.source,this.cache,!0)}changePartialMemoizationBehaviour(){return new P(this.source)}},P=class{source;cache=j();constructor(e){this.source=e}[Symbol.iterator](){return new F(this.source,this.cache,!1)}changePartialMemoizationBehaviour(){return new N(this.source)}},F=class extends m{source;cache;drainFirst;index=0;constructor(e,t,n){super(),this.source=e,this.cache=t,this.drainFirst=n}advance(){if(this.drainFirst)for(;M(this.source,this.cache););return this.index<this.cache.values.length||M(this.source,this.cache)?s(this.cache.values[this.index++]):c()}};function I(e,t){return l(e),o(e,a(t),-1)}function L(e,t,n){let r=typeof t==`number`,i=r?e:0,a=r?t:e;if(!r&&n!==void 0)throw Error(`The "options" parameter must be the second argument when "start" is omitted`);let o=r?n:t;o!==void 0&&ee(o,`options`);let{step:s=1,reverse:c=!1}=o??{};f(s,`step`);let l=le(i,a,Math.abs(s),c);return l.length>0?new h(()=>new ue(l.first,l.step,l.length)):v()}function le(e,t,n,r){let i=t<e?-n:n,a=Math.ceil(Math.abs(t-e)/n);return r?{first:e+(a-1)*i,step:-i,length:a}:{first:e,step:i,length:a}}var ue=class extends m{first;step;length;index=0;constructor(e,t,n){super(),this.first=e,this.step=t,this.length=n}advance(){return this.index>=this.length?c():s(this.first+this.index++*this.step)}};function R(e,...t){if(l(e),t.length===1)return de(e,t[0]);let[n,r]=t;u(r,`reducer`);let i=n,a=0;for(let t of e)i=r(i,t,a++);return i}function de(e,t){u(t,`reducer`);let n,r=0;for(let i of e)n=r===0?i:t(n,i,r),r++;if(r===0)throw Error(`The "sourceIterable" must not be empty when "reduce" has no seed`);return n}function z(e,t){return d(t,`count`),_(t,t=>t>0?[e,t-1]:void 0)}function B(e,t){return l(e),d(t,`count`),new h(()=>new V(e,t))}var V=class extends g{count;constructor(e,t){super(e),this.count=t}advance(){for(;this.index<this.count;){let e=this.source.next();if(e.done===!0)return e;this.index++}return this.source.next()}};function H(e,t){if(l(e),t===void 0){for(let t of e)return!0;return!1}u(t,`predicate`);let n=0;for(let r of e)if(t(r,n++))return!0;return!1}function U(e,t){return l(e),d(t,`count`),new h(()=>new fe(e,t))}var fe=class extends g{count;constructor(e,t){super(e),this.count=t}advance(){if(this.index>=this.count)return this.source.return?.(),c();let e=this.source.next();return e.done===!0?e:(this.index++,s(e.value))}};function W(e,t){return l(e),u(t,`tapper`),new h(()=>new pe(e,t))}var pe=class extends g{tapper;constructor(e,t){super(e),this.tapper=t}advance(){let e=this.source.next();if(e.done===!0)return e;try{this.tapper(e.value,this.index++)}catch(e){throw this.closeAfterCallbackError(),e}return e}};function G(e,t){return l(e),u(t,`tapper`),new h(()=>(t(e,0),e[Symbol.iterator]()))}var me=n({collectToArray:()=>p,empty:()=>v,filter:()=>y,flatMap:()=>b,forEach:()=>C,forEachAsync:()=>w,getMemoizeDefaultOptions:()=>k,map:()=>T,materialize:()=>E,max:()=>O,memoize:()=>A,min:()=>I,range:()=>L,reduce:()=>R,repeat:()=>z,skip:()=>B,some:()=>H,take:()=>U,tap:()=>W,tapChain:()=>G}),K=Symbol.for(`iterable-linq-utility.IIterableLinq`);function q(e){return new J(e)}var J=class{iterable;constructor(e){this.iterable=e}[Symbol.iterator](){return this.iterable[Symbol.iterator]()}collectToArray(){return p(this.iterable)}filter(e){return q(y(this.iterable,e))}flatMap(e){return q(b(this.iterable,e))}forEach(e){return C(this.iterable,e)}forEachAsync(e){return w(this.iterable,e)}map(e){return q(T(this.iterable,e))}materialize(){return q(E(this.iterable))}max(e){return O(this.iterable,e)}memoize(e){return q(A(this.iterable,e))}min(e){return I(this.iterable,e)}reduce(...e){return e.length===1?R(this.iterable,e[0]):R(this.iterable,e[0],e[1])}skip(e){return q(B(this.iterable,e))}some(e){return H(this.iterable,e)}take(e){return q(U(this.iterable,e))}tap(e){return q(W(this.iterable,e))}tapChain(e){return q(G(this.iterable,e))}tapChainCreation(e){u(e,`chainCreationTapper`);let t=this;return e(t),t}};Object.defineProperty(J.prototype,K,{value:!0,enumerable:!1,writable:!1,configurable:!1});function Y(){return J.prototype}function he(e){return typeof e==`object`&&!!e&&e[K]===!0}function X(e,t){let n=Object.getOwnPropertyDescriptor(Y(),e);Object.defineProperty(Y(),e,{value:t,enumerable:!1,writable:n?.writable??!1,configurable:!0})}function Z(e,t){te(e,`name`),u(t,`implementation`)}function Q(e,t){if(Z(e,t),e in q([]))throw Error(`"${e}" already exists on IIterableLinq: use override() to replace it`);X(e,t)}function ge(e,t){Z(e,t);let n=e;if(!(n!==`constructor`&&Object.prototype.hasOwnProperty.call(Y(),n)))throw Error(`"${n}" is not a method of IIterableLinq: use extend() to add it`);X(n,t)}function _e(){return $(v())}function $(e){return l(e),q(e)}function ve(e,t,n){if(typeof t==`number`)return $(L(e,t,n));if(n!==void 0)throw Error(`The "options" parameter must be the second argument when "start" is omitted`);return $(L(e,t))}function ye(e,t){return $(z(e,t))}Object.defineProperty(e,"Functions",{enumerable:!0,get:function(){return me}}),e.Unit=x,e.empty=_e,e.extend=Q,e.from=$,e.fromRange=ve,e.isIterableLinq=he,e.override=ge,e.repeat=ye,e.unit=S});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iterable-linq-utility",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "An Iterable mutation utility inspired by .net Linq and Javascript Array interface",
5
5
  "type": "module",
6
6
  "main": "./dist/iterable-linq-utility.umd.cjs",
@@ -25,6 +25,7 @@
25
25
  "build": "tsc -p tsconfig.build.json && vite build && cp dist/index.d.ts dist/index.d.cts",
26
26
  "check:package": "attw --pack .",
27
27
  "check:changeset": "changeset status --since=origin/main",
28
+ "check:commits": "node scripts/check-commits.ts",
28
29
  "check:since": "node scripts/check-since.ts",
29
30
  "check:instructions": "node scripts/check-instructions.ts",
30
31
  "check:structure": "node scripts/check-structure.ts",
@@ -65,6 +66,7 @@
65
66
  "@vitest/coverage-istanbul": "^5.0.2",
66
67
  "@vitest/ui": "^5.0.2",
67
68
  "eslint": "^10.11.0",
69
+ "eslint-plugin-perfectionist": "^5.12.1",
68
70
  "eslint-plugin-tsdoc": "^0.5.3",
69
71
  "globals": "^17.12.0",
70
72
  "typescript": "^6.0.3",
@@ -73,5 +75,5 @@
73
75
  "vite-plugin-dts": "^5.1.1",
74
76
  "vitest": "^5.0.2"
75
77
  },
76
- "packageManager": "pnpm@11.24.0"
78
+ "packageManager": "pnpm@12.8.1"
77
79
  }