iterable-linq-utility 0.9.0 → 0.10.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 CHANGED
@@ -86,6 +86,22 @@ declare function average<T>(iterable: Iterable<T>, selector: Mapper<T, number> |
86
86
  */
87
87
  export declare type ChainMethod = (this: IIterableLinq<unknown>, ...args: any[]) => unknown;
88
88
 
89
+ /**
90
+ * Lazily yields arrays of `size` values; the last array has the remaining values and can be shorter.
91
+ * Each array is new, and is yielded once its values have been read, so `chunk` works with infinite sources.
92
+ * @operation `Transformation`
93
+ * @param iterable - the source `Iterable`
94
+ * @param size - how many values in each array; must be a positive integer
95
+ * @returns a lazy, re-runnable `Iterable` of arrays of at most `size` values
96
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `size` is not a positive integer (`0`, fractions, `NaN` and `Infinity` included)
97
+ * @example
98
+ * ```ts
99
+ * Array.from(Functions.chunk([1, 2, 3, 4, 5], 2)); // [[1, 2], [3, 4], [5]]
100
+ * ```
101
+ * @since 0.10.0
102
+ */
103
+ declare function chunk<T>(iterable: Iterable<T>, size: number): Iterable<T[]>;
104
+
89
105
  /**
90
106
  * Collects the values of `iterable` into an `Array`.
91
107
  * @operation `Action`
@@ -100,6 +116,55 @@ export declare type ChainMethod = (this: IIterableLinq<unknown>, ...args: any[])
100
116
  */
101
117
  declare function collectToArray<T>(iterable: Iterable<T>): T[];
102
118
 
119
+ /**
120
+ * Collects the values of `iterable` into a `Map`, with the key returned by `keySelector`.
121
+ * A later value with the same key (`SameValueZero`, as in `Map`) replaces the earlier one.
122
+ * If `keySelector` throws, the source is closed and the error propagates.
123
+ * @operation `Action`
124
+ * @param iterable - the source `Iterable`
125
+ * @param keySelector - called with each value and its index; returns the key of the value
126
+ * @returns a `Map` from each key to the last value with that key; an empty `Map` when `iterable` is empty
127
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `keySelector` is not a function
128
+ * @example
129
+ * ```ts
130
+ * Functions.collectToMap([{ id: 1, name: 'a' }, { id: 2, name: 'b' }], v => v.id); // Map { 1 => { id: 1, name: 'a' }, 2 => { id: 2, name: 'b' } }
131
+ * ```
132
+ * @since 0.10.0
133
+ */
134
+ declare function collectToMap<T, K>(iterable: Iterable<T>, keySelector: Mapper<T, K>): Map<K, T>;
135
+
136
+ /**
137
+ * Collects the values of `iterable` into a `Map`, with the key returned by `keySelector` and the value returned by `valueSelector`.
138
+ * A later value with the same key (`SameValueZero`, as in `Map`) replaces the earlier one.
139
+ * If `keySelector` or `valueSelector` throws, the source is closed and the error propagates.
140
+ * @operation `Action`
141
+ * @param iterable - the source `Iterable`
142
+ * @param keySelector - called with each value and its index; returns the key of the value
143
+ * @param valueSelector - called with each value and its index; returns the value to store; `undefined` stores the value itself
144
+ * @returns a `Map` from each key to the value selected from the last value with that key; an empty `Map` when `iterable` is empty
145
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, if `keySelector` is not a function, or if a provided `valueSelector` is not a function
146
+ * @example
147
+ * ```ts
148
+ * Functions.collectToMap([{ id: 1, name: 'a' }, { id: 2, name: 'b' }], v => v.id, v => v.name); // Map { 1 => 'a', 2 => 'b' }
149
+ * ```
150
+ * @since 0.10.0
151
+ */
152
+ declare function collectToMap<T, K, V>(iterable: Iterable<T>, keySelector: Mapper<T, K>, valueSelector: Mapper<T, V> | undefined): Map<K, V>;
153
+
154
+ /**
155
+ * Collects the values of `iterable` into a `Set`: a value equal to an earlier one (`SameValueZero`, as in `Set`) is left out.
156
+ * @operation `Action`
157
+ * @param iterable - the source `Iterable`
158
+ * @returns the distinct values, in the order of their first occurrence; an empty `Set` when `iterable` is empty
159
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
160
+ * @example
161
+ * ```ts
162
+ * Functions.collectToSet([1, 2, 1, 3]); // Set { 1, 2, 3 }
163
+ * ```
164
+ * @since 0.10.0
165
+ */
166
+ declare function collectToSet<T>(iterable: Iterable<T>): Set<T>;
167
+
103
168
  /**
104
169
  * How `min` and `max` compare two values. One of:
105
170
  * - a compare function `(a, b) => number`: negative if `a` comes before `b`, 0 if they are equal, positive if `a` comes after `b`;
@@ -166,6 +231,22 @@ declare function count<T>(iterable: Iterable<T>): number;
166
231
  */
167
232
  declare function count<T>(iterable: Iterable<T>, predicate: Predicate<T> | undefined): number;
168
233
 
234
+ /**
235
+ * Lazily yields the values of `iterable`, or only `value` when `iterable` is empty.
236
+ * @operation `Transformation`
237
+ * @param iterable - the source `Iterable`
238
+ * @param value - the value yielded when `iterable` has no values
239
+ * @returns a lazy, re-runnable `Iterable` of the values, or of `value` alone
240
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
241
+ * @example
242
+ * ```ts
243
+ * Array.from(Functions.defaultIfEmpty([1, 2], 0)); // [1, 2]
244
+ * Array.from(Functions.defaultIfEmpty([], 0)); // [0]
245
+ * ```
246
+ * @since 0.10.0
247
+ */
248
+ declare function defaultIfEmpty<T>(iterable: Iterable<T>, value: T): Iterable<T>;
249
+
169
250
  /**
170
251
  * Lazily yields the first value for each distinct value or selected key, in source order.
171
252
  * Keys use `SameValueZero`, like `Set`; original values are preserved.
@@ -207,6 +288,20 @@ export declare function empty<T>(): IIterableLinq<T>;
207
288
  */
208
289
  declare function empty_2<T>(): Iterable<T>;
209
290
 
291
+ /**
292
+ * Lazily yields `[index, value]` pairs, like `Array.prototype.entries`.
293
+ * @operation `Transformation`
294
+ * @param iterable - the source `Iterable`
295
+ * @returns a lazy, re-runnable `Iterable` of pairs of the index, from 0, and the value
296
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`
297
+ * @example
298
+ * ```ts
299
+ * Array.from(Functions.entries(['a', 'b'])); // [[0, 'a'], [1, 'b']]
300
+ * ```
301
+ * @since 0.10.0
302
+ */
303
+ declare function entries<T>(iterable: Iterable<T>): Iterable<[number, T]>;
304
+
210
305
  /**
211
306
  * Tells whether every value satisfies `predicate`; stops and closes the source at the first rejected value.
212
307
  * @operation `Action`
@@ -372,6 +467,34 @@ declare function findLast<T>(iterable: Iterable<T>, predicate: Predicate<T>): T
372
467
  */
373
468
  declare function findLastIndex<T>(iterable: Iterable<T>, predicate: Predicate<T>): number;
374
469
 
470
+ /**
471
+ * Lazily flattens the nested iterables of `iterable` up to `depth` levels, like `Array.prototype.flat` for any `Iterable`.
472
+ * Strings, primitive or `String` objects, are not flattened. Nested arrays are read by index: their `[Symbol.iterator]` is not called.
473
+ * If a nested iterable throws, the iterables that contain it and the source are closed, and the error propagates.
474
+ * @operation `Transformation`
475
+ * @param iterable - the source `Iterable`
476
+ * @param depth - how many levels to flatten, `1` by default; a non-negative integer or `Infinity`
477
+ * @returns a lazy, re-runnable `Iterable` of the flattened values
478
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `depth` is not a non-negative integer or `Infinity`
479
+ * @example
480
+ * ```ts
481
+ * Array.from(Functions.flat([1, [2, [3]], new Set([4])])); // [1, 2, [3], 4]
482
+ * Array.from(Functions.flat([1, [2, [3]]], Infinity)); // [1, 2, 3]
483
+ * ```
484
+ * @since 0.10.0
485
+ */
486
+ declare function flat<T, D extends number = 1>(iterable: Iterable<T>, depth?: D): Iterable<FlatIterable<T, D>>;
487
+
488
+ /**
489
+ * The type of the values of `flat` with `Depth` levels: like `FlatArray`, for any `Iterable` except strings.
490
+ * A `Depth` of type `number` (for example `Infinity`) gives a wide type, as `FlatArray` does.
491
+ * @since 0.10.0
492
+ */
493
+ export declare type FlatIterable<T, Depth extends number> = {
494
+ done: T;
495
+ recur: T extends string | String ? T : T extends Iterable<infer U> ? FlatIterable<U, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][Depth]> : T;
496
+ }[Depth extends 0 ? 'done' : 'recur'];
497
+
375
498
  /**
376
499
  * Lazily maps each value to an `Iterable` and flattens the results.
377
500
  * Each inner `Iterable` is read completely before the next value is mapped.
@@ -487,17 +610,23 @@ declare namespace Functions {
487
610
  append,
488
611
  at,
489
612
  average,
613
+ chunk,
490
614
  collectToArray,
615
+ collectToMap,
616
+ collectToSet,
491
617
  concat,
492
618
  count,
619
+ defaultIfEmpty,
493
620
  distinct,
494
621
  empty_2 as empty,
622
+ entries,
495
623
  every,
496
624
  filter,
497
625
  find,
498
626
  findIndex,
499
627
  findLast,
500
628
  findLastIndex,
629
+ flat,
501
630
  flatMap,
502
631
  forEach,
503
632
  forEachAsync,
@@ -514,6 +643,7 @@ declare namespace Functions {
514
643
  prepend,
515
644
  range,
516
645
  reduce,
646
+ reduceRight,
517
647
  repeat_2 as repeat,
518
648
  reverse,
519
649
  sequenceEqual,
@@ -528,7 +658,9 @@ declare namespace Functions {
528
658
  takeLast,
529
659
  takeWhile,
530
660
  tap,
531
- tapChain
661
+ tapChain,
662
+ withValue as with,
663
+ zip
532
664
  }
533
665
  }
534
666
  export { Functions }
@@ -623,6 +755,20 @@ export declare interface IIterableLinqBase<T> {
623
755
  * @since 0.7.0
624
756
  */
625
757
  average(selector: Mapper<T, number> | undefined): number | undefined;
758
+ /**
759
+ * Lazily yields arrays of `size` values; the last array has the remaining values and can be shorter.
760
+ * Each array is new, and is yielded once its values have been read, so `chunk` works with infinite chains.
761
+ * @operation `Transformation`
762
+ * @param size - how many values in each array; must be a positive integer
763
+ * @returns a lazy, re-runnable chain of arrays of at most `size` values
764
+ * @throws Error if `size` is not a positive integer (`0`, fractions, `NaN` and `Infinity` included)
765
+ * @example
766
+ * ```ts
767
+ * IterableLinq.from([1, 2, 3, 4, 5]).chunk(2).collectToArray(); // [[1, 2], [3, 4], [5]]
768
+ * ```
769
+ * @since 0.10.0
770
+ */
771
+ chunk(size: number): IIterableLinq<T[]>;
626
772
  /**
627
773
  * Runs the chain and collects its values into an `Array`.
628
774
  * @operation `Action`
@@ -634,6 +780,48 @@ export declare interface IIterableLinqBase<T> {
634
780
  * @since 0.0.1
635
781
  */
636
782
  collectToArray(): T[];
783
+ /**
784
+ * Runs the chain and collects its values into a `Map`, with the key returned by `keySelector`.
785
+ * A later value with the same key (`SameValueZero`, as in `Map`) replaces the earlier one.
786
+ * If `keySelector` throws, the source is closed and the error propagates.
787
+ * @operation `Action`
788
+ * @param keySelector - called with each value and its index; returns the key of the value
789
+ * @returns a `Map` from each key to the last value with that key; an empty `Map` when the chain is empty
790
+ * @throws Error if `keySelector` is not a function
791
+ * @example
792
+ * ```ts
793
+ * IterableLinq.from([{ id: 1, name: 'a' }, { id: 2, name: 'b' }]).collectToMap(v => v.id); // Map { 1 => { id: 1, name: 'a' }, 2 => { id: 2, name: 'b' } }
794
+ * ```
795
+ * @since 0.10.0
796
+ */
797
+ collectToMap<K>(keySelector: Mapper<T, K>): Map<K, T>;
798
+ /**
799
+ * Runs the chain and collects its values into a `Map`, with the key returned by `keySelector` and the value returned by `valueSelector`.
800
+ * A later value with the same key (`SameValueZero`, as in `Map`) replaces the earlier one.
801
+ * If `keySelector` or `valueSelector` throws, the source is closed and the error propagates.
802
+ * @operation `Action`
803
+ * @param keySelector - called with each value and its index; returns the key of the value
804
+ * @param valueSelector - called with each value and its index; returns the value to store; `undefined` stores the value itself
805
+ * @returns a `Map` from each key to the value selected from the last value with that key; an empty `Map` when the chain is empty
806
+ * @throws Error if `keySelector` is not a function, or if a provided `valueSelector` is not a function
807
+ * @example
808
+ * ```ts
809
+ * IterableLinq.from([{ id: 1, name: 'a' }, { id: 2, name: 'b' }]).collectToMap(v => v.id, v => v.name); // Map { 1 => 'a', 2 => 'b' }
810
+ * ```
811
+ * @since 0.10.0
812
+ */
813
+ collectToMap<K, V>(keySelector: Mapper<T, K>, valueSelector: Mapper<T, V> | undefined): Map<K, V>;
814
+ /**
815
+ * Runs the chain and collects its values into a `Set`: a value equal to an earlier one (`SameValueZero`, as in `Set`) is left out.
816
+ * @operation `Action`
817
+ * @returns the distinct values, in the order of their first occurrence; an empty `Set` when the chain is empty
818
+ * @example
819
+ * ```ts
820
+ * IterableLinq.from([1, 2, 1, 3]).collectToSet(); // Set { 1, 2, 3 }
821
+ * ```
822
+ * @since 0.10.0
823
+ */
824
+ collectToSet(): Set<T>;
637
825
  /**
638
826
  * Yields the values of the chain, then the values of each iterable in `others`, in order.
639
827
  * Each iterable is opened only when the previous one ends, so the iterables after an infinite chain are never read.
@@ -674,6 +862,19 @@ export declare interface IIterableLinqBase<T> {
674
862
  * @since 0.5.0
675
863
  */
676
864
  count(predicate: Predicate<T> | undefined): number;
865
+ /**
866
+ * Lazily yields the values of the chain, or only `value` when the chain is empty.
867
+ * @operation `Transformation`
868
+ * @param value - the value yielded when the chain has no values
869
+ * @returns a lazy, re-runnable chain of the values, or of `value` alone
870
+ * @example
871
+ * ```ts
872
+ * IterableLinq.from([1, 2]).defaultIfEmpty(0).collectToArray(); // [1, 2]
873
+ * IterableLinq.empty<number>().defaultIfEmpty(0).collectToArray(); // [0]
874
+ * ```
875
+ * @since 0.10.0
876
+ */
877
+ defaultIfEmpty(value: T): IIterableLinq<T>;
677
878
  /**
678
879
  * Yields the first value for each distinct value or selected key, in source order.
679
880
  * Keys use `SameValueZero`, like `Set`; original values are preserved.
@@ -690,6 +891,17 @@ export declare interface IIterableLinqBase<T> {
690
891
  * @since 0.5.0
691
892
  */
692
893
  distinct<K>(keySelector?: Mapper<T, K>): IIterableLinq<T>;
894
+ /**
895
+ * Lazily yields `[index, value]` pairs, like `Array.prototype.entries`.
896
+ * @operation `Transformation`
897
+ * @returns a lazy, re-runnable chain of pairs of the index, from 0, and the value
898
+ * @example
899
+ * ```ts
900
+ * IterableLinq.from(['a', 'b']).entries().collectToArray(); // [[0, 'a'], [1, 'b']]
901
+ * ```
902
+ * @since 0.10.0
903
+ */
904
+ entries(): IIterableLinq<[number, T]>;
693
905
  /**
694
906
  * Tells whether every value satisfies `predicate`; stops and closes the source at the first rejected value.
695
907
  * @operation `Action`
@@ -815,6 +1027,22 @@ export declare interface IIterableLinqBase<T> {
815
1027
  * @since 0.6.0
816
1028
  */
817
1029
  findLastIndex(predicate: Predicate<T>): number;
1030
+ /**
1031
+ * Lazily flattens the nested iterables of the chain up to `depth` levels, like `Array.prototype.flat` for any `Iterable`.
1032
+ * Strings, primitive or `String` objects, are not flattened. Nested arrays are read by index: their `[Symbol.iterator]` is not called.
1033
+ * If a nested iterable throws, the iterables that contain it and the source are closed, and the error propagates.
1034
+ * @operation `Transformation`
1035
+ * @param depth - how many levels to flatten, `1` by default; a non-negative integer or `Infinity`
1036
+ * @returns a lazy, re-runnable chain of the flattened values
1037
+ * @throws Error if `depth` is not a non-negative integer or `Infinity`
1038
+ * @example
1039
+ * ```ts
1040
+ * IterableLinq.from([1, [2, [3]], new Set([4])]).flat().collectToArray(); // [1, 2, [3], 4]
1041
+ * IterableLinq.from([1, [2, [3]]]).flat(Infinity).collectToArray(); // [1, 2, 3]
1042
+ * ```
1043
+ * @since 0.10.0
1044
+ */
1045
+ flat<D extends number = 1>(depth?: D): IIterableLinq<FlatIterable<T, D>>;
818
1046
  /**
819
1047
  * Maps each value to an `Iterable` and flattens the results into one chain.
820
1048
  * Each inner `Iterable` is read completely before the next value of the chain is mapped.
@@ -1033,6 +1261,35 @@ export declare interface IIterableLinqBase<T> {
1033
1261
  * @since 0.0.10
1034
1262
  */
1035
1263
  reduce<R>(neutralElement: R, reducer: Reducer<T, R>): R;
1264
+ /**
1265
+ * Runs the chain and accumulates its values into a single result, from the last value to the first, starting from the last value.
1266
+ * The whole chain runs before `reducer` is called.
1267
+ * @operation `Action`
1268
+ * @param reducer - called with the accumulator, each value from the second-to-last one back to the first, and its index in the chain; returns the new accumulator
1269
+ * @returns the final accumulator; the only value when the chain has one value, without calling `reducer`
1270
+ * @throws Error if the chain is empty or if `reducer` is not a function
1271
+ * @example
1272
+ * ```ts
1273
+ * IterableLinq.from(['a', 'b', 'c']).reduceRight((acc, v) => acc + v); // 'cba'
1274
+ * ```
1275
+ * @since 0.10.0
1276
+ */
1277
+ reduceRight(reducer: Reducer<T, T>): T;
1278
+ /**
1279
+ * Runs the chain and accumulates its values into a single result, from the last value to the first.
1280
+ * The whole chain runs before `reducer` is called.
1281
+ * @operation `Action`
1282
+ * @param neutralElement - the initial accumulator (the seed)
1283
+ * @param reducer - called with the accumulator, each value from the last one back to the first, and its index in the chain; returns the new accumulator
1284
+ * @returns the final accumulator; `neutralElement` when the chain is empty
1285
+ * @throws Error if `reducer` is not a function
1286
+ * @example
1287
+ * ```ts
1288
+ * IterableLinq.from([1, 2, 3]).reduceRight('', (acc, v) => acc + v); // '321'
1289
+ * ```
1290
+ * @since 0.10.0
1291
+ */
1292
+ reduceRight<R>(neutralElement: R, reducer: Reducer<T, R>): R;
1036
1293
  /**
1037
1294
  * Lazily yields the values in reverse order. Unlike `Array.prototype.reverse`, the source is not changed.
1038
1295
  * The whole chain runs before the first value is yielded, so `reverse` does not end on an infinite chain.
@@ -1327,6 +1584,40 @@ export declare interface IIterableLinqBase<T> {
1327
1584
  * @since 0.0.10
1328
1585
  */
1329
1586
  tapChainCreation(chainCreationTapper: (chain: IIterableLinq<T>) => Unit): IIterableLinq<T>;
1587
+ /**
1588
+ * Lazily yields the values of the chain, with `value` in place of the value at `index`, like `Array.prototype.with`; a negative index counts from the end.
1589
+ * A non-negative index yields the values as they are read. A negative index yields each value once `-index` more values have been read,
1590
+ * keeping only those `-index` values.
1591
+ * @operation `Transformation`
1592
+ * @param index - an integer; `-1` is the last value
1593
+ * @param value - the value yielded in place of the value at `index`
1594
+ * @returns a lazy, re-runnable chain of the values, with `value` at `index`
1595
+ * @throws Error if `index` is not an integer (fractions, `NaN` and `Infinity` included); when the chain ends, if it has no value at `index`
1596
+ * @example
1597
+ * ```ts
1598
+ * IterableLinq.from([1, 2, 3]).with(1, 20).collectToArray(); // [1, 20, 3]
1599
+ * IterableLinq.from([1, 2, 3]).with(-1, 30).collectToArray(); // [1, 2, 30]
1600
+ * ```
1601
+ * @since 0.10.0
1602
+ */
1603
+ with(index: number, value: T): IIterableLinq<T>;
1604
+ /**
1605
+ * Lazily yields tuples of the values at the same position in the chain and in each of `others`.
1606
+ * It stops at the end of the shortest iterable and closes the others; if an iterable throws, the others are closed and the error propagates.
1607
+ * @operation `Transformation`
1608
+ * @param others - the iterables read side by side with the chain
1609
+ * @returns a lazy, re-runnable chain of tuples, as many as the values of the shortest iterable
1610
+ * @throws Error if a value of `others` is missing or does not implement `[Symbol.iterator]`
1611
+ * @example
1612
+ * ```ts
1613
+ * IterableLinq.from([1, 2, 3]).zip(['a', 'b']).collectToArray(); // [[1, 'a'], [2, 'b']]
1614
+ * IterableLinq.from([1, 2]).zip(['a', 'b'], [true, false]).collectToArray(); // [[1, 'a', true], [2, 'b', false]]
1615
+ * ```
1616
+ * @since 0.10.0
1617
+ */
1618
+ zip<U extends unknown[]>(...others: {
1619
+ [K in keyof U]: Iterable<U[K]>;
1620
+ }): IIterableLinq<[T, ...U]>;
1330
1621
  }
1331
1622
 
1332
1623
  /**
@@ -1640,6 +1931,39 @@ declare function reduce<T, R>(iterable: Iterable<T>, neutralElement: R, reducer:
1640
1931
  */
1641
1932
  export declare type Reducer<T, R> = (acc: R, value: T, index: number) => R;
1642
1933
 
1934
+ /**
1935
+ * Accumulates the values of `iterable` into a single result, from the last value to the first, starting from the last value.
1936
+ * The whole source is read before `reducer` is called.
1937
+ * @operation `Action`
1938
+ * @param iterable - the source `Iterable`
1939
+ * @param reducer - called with the accumulator, each value from the second-to-last one back to the first, and its index in the source; returns the new accumulator
1940
+ * @returns the final accumulator; the only value when `iterable` has one value, without calling `reducer`
1941
+ * @throws Error if `iterable` is missing, does not implement `[Symbol.iterator]` or is empty, or if `reducer` is not a function
1942
+ * @example
1943
+ * ```ts
1944
+ * Functions.reduceRight(['a', 'b', 'c'], (acc, v) => acc + v); // 'cba'
1945
+ * ```
1946
+ * @since 0.10.0
1947
+ */
1948
+ declare function reduceRight<T>(iterable: Iterable<T>, reducer: Reducer<T, T>): T;
1949
+
1950
+ /**
1951
+ * Accumulates the values of `iterable` into a single result, from the last value to the first.
1952
+ * The whole source is read before `reducer` is called.
1953
+ * @operation `Action`
1954
+ * @param iterable - the source `Iterable`
1955
+ * @param neutralElement - the initial accumulator (the seed)
1956
+ * @param reducer - called with the accumulator, each value from the last one back to the first, and its index in the source; returns the new accumulator
1957
+ * @returns the final accumulator; `neutralElement` when `iterable` is empty
1958
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `reducer` is not a function
1959
+ * @example
1960
+ * ```ts
1961
+ * Functions.reduceRight([1, 2, 3], '', (acc, v) => acc + v); // '321'
1962
+ * ```
1963
+ * @since 0.10.0
1964
+ */
1965
+ declare function reduceRight<T, R>(iterable: Iterable<T>, neutralElement: R, reducer: Reducer<T, R>): R;
1966
+
1643
1967
  /**
1644
1968
  * Starts a chain that yields `value` `count` times.
1645
1969
  * @param value - the value to repeat
@@ -2023,4 +2347,44 @@ export declare class Unit {
2023
2347
  */
2024
2348
  export declare function unit(): Unit;
2025
2349
 
2350
+ /**
2351
+ * Lazily yields the values of `iterable`, with `value` in place of the value at `index`, like `Array.prototype.with`; a negative index counts from the end.
2352
+ * A non-negative index yields the values as they are read. A negative index yields each value once `-index` more values have been read,
2353
+ * keeping only those `-index` values.
2354
+ * Exported as `with`, a reserved word that cannot name a function declaration.
2355
+ * @operation `Transformation`
2356
+ * @param iterable - the source `Iterable`
2357
+ * @param index - an integer; `-1` is the last value
2358
+ * @param value - the value yielded in place of the value at `index`
2359
+ * @returns a lazy, re-runnable `Iterable` of the values, with `value` at `index`
2360
+ * @throws Error if `iterable` is missing or does not implement `[Symbol.iterator]`, or if `index` is not an integer (fractions, `NaN` and `Infinity` included);
2361
+ * when the source ends, if it has no value at `index`
2362
+ * @example
2363
+ * ```ts
2364
+ * Array.from(Functions.with([1, 2, 3], 1, 20)); // [1, 20, 3]
2365
+ * Array.from(Functions.with([1, 2, 3], -1, 30)); // [1, 2, 30]
2366
+ * ```
2367
+ * @since 0.10.0
2368
+ */
2369
+ declare function withValue<T>(iterable: Iterable<T>, index: number, value: T): Iterable<T>;
2370
+
2371
+ /**
2372
+ * Lazily yields tuples of the values at the same position in `iterable` and in each of `others`.
2373
+ * It stops at the end of the shortest iterable and closes the others; if an iterable throws, the others are closed and the error propagates.
2374
+ * @operation `Transformation`
2375
+ * @param iterable - the source `Iterable`
2376
+ * @param others - the iterables read side by side with the source
2377
+ * @returns a lazy, re-runnable `Iterable` of tuples, as many as the values of the shortest iterable
2378
+ * @throws Error if `iterable` or a value of `others` is missing or does not implement `[Symbol.iterator]`
2379
+ * @example
2380
+ * ```ts
2381
+ * Array.from(Functions.zip([1, 2, 3], ['a', 'b'])); // [[1, 'a'], [2, 'b']]
2382
+ * Array.from(Functions.zip([1, 2], ['a', 'b'], [true, false])); // [[1, 'a', true], [2, 'b', false]]
2383
+ * ```
2384
+ * @since 0.10.0
2385
+ */
2386
+ declare function zip<T, U extends unknown[]>(iterable: Iterable<T>, ...others: {
2387
+ [K in keyof U]: Iterable<U[K]>;
2388
+ }): Iterable<[T, ...U]>;
2389
+
2026
2390
  export { }