@rimbu/common 0.8.2 → 0.9.2
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 +26 -15
- package/dist/main/async-optlazy.js +6 -2
- package/dist/main/async-optlazy.js.map +1 -1
- package/dist/main/async-reducer.js +22 -22
- package/dist/main/async-reducer.js.map +1 -1
- package/dist/main/collect.js +1 -1
- package/dist/main/comp.js +29 -6
- package/dist/main/comp.js.map +1 -1
- package/dist/main/eq.js +27 -1
- package/dist/main/eq.js.map +1 -1
- package/dist/main/err.js +3 -1
- package/dist/main/err.js.map +1 -1
- package/dist/main/index-range.js +1 -1
- package/dist/main/index-range.js.map +1 -1
- package/dist/main/index.js +6 -1
- package/dist/main/index.js.map +1 -1
- package/dist/main/internal.js +13 -13
- package/dist/main/internal.js.map +1 -1
- package/dist/main/optlazy.js +4 -0
- package/dist/main/optlazy.js.map +1 -1
- package/dist/main/range.js.map +1 -1
- package/dist/main/reducer.js +75 -19
- package/dist/main/reducer.js.map +1 -1
- package/dist/main/update.js +3 -1
- package/dist/main/update.js.map +1 -1
- package/dist/module/async-optlazy.js +4 -0
- package/dist/module/async-optlazy.js.map +1 -1
- package/dist/module/async-reducer.js +12 -12
- package/dist/module/async-reducer.js.map +1 -1
- package/dist/module/collect.js +1 -1
- package/dist/module/comp.js +28 -5
- package/dist/module/comp.js.map +1 -1
- package/dist/module/eq.js +26 -0
- package/dist/module/eq.js.map +1 -1
- package/dist/module/err.js +2 -0
- package/dist/module/err.js.map +1 -1
- package/dist/module/index-range.js.map +1 -1
- package/dist/module/index.js +5 -0
- package/dist/module/index.js.map +1 -1
- package/dist/module/optlazy.js +4 -0
- package/dist/module/optlazy.js.map +1 -1
- package/dist/module/range.js.map +1 -1
- package/dist/module/reducer.js +75 -19
- package/dist/module/reducer.js.map +1 -1
- package/dist/module/update.js +3 -1
- package/dist/module/update.js.map +1 -1
- package/dist/types/async-optlazy.d.ts +4 -0
- package/dist/types/async-reducer.d.ts +37 -22
- package/dist/types/collect.d.ts +2 -2
- package/dist/types/comp.d.ts +32 -5
- package/dist/types/eq.d.ts +26 -0
- package/dist/types/err.d.ts +2 -0
- package/dist/types/index-range.d.ts +14 -13
- package/dist/types/index.d.ts +5 -0
- package/dist/types/optlazy.d.ts +4 -0
- package/dist/types/range.d.ts +11 -10
- package/dist/types/reducer.d.ts +100 -29
- package/dist/types/types.d.ts +0 -4
- package/dist/types/update.d.ts +3 -1
- package/package.json +6 -4
- package/src/async-optlazy.ts +4 -0
- package/src/async-reducer.ts +37 -22
- package/src/collect.ts +2 -2
- package/src/comp.ts +40 -13
- package/src/eq.ts +26 -0
- package/src/err.ts +2 -0
- package/src/index-range.ts +14 -13
- package/src/index.ts +6 -0
- package/src/optlazy.ts +4 -0
- package/src/range.ts +11 -10
- package/src/reducer.ts +107 -31
- package/src/types.ts +0 -5
- package/src/update.ts +3 -1
package/dist/types/reducer.d.ts
CHANGED
|
@@ -41,59 +41,72 @@ export declare namespace Reducer {
|
|
|
41
41
|
stateToResult(state: S): O;
|
|
42
42
|
/**
|
|
43
43
|
* Returns a `Reducer` instance that only passes values to the reducer that satisy the given `pred` predicate.
|
|
44
|
-
* @param pred - a function that returns true if the value should be passed to the reducer based on the following inputs
|
|
45
|
-
* - value: the current input value
|
|
46
|
-
* - index: the current input index
|
|
44
|
+
* @param pred - a function that returns true if the value should be passed to the reducer based on the following inputs:<br/>
|
|
45
|
+
* - value: the current input value<br/>
|
|
46
|
+
* - index: the current input index<br/>
|
|
47
47
|
* - halt: function that, when called, ensures no more new values are passed to the reducer
|
|
48
48
|
* @example
|
|
49
|
+
* ```ts
|
|
49
50
|
* Reducer.sum.filterInput(v => v > 10)
|
|
50
51
|
* // this reducer will only sum values larger than 10
|
|
52
|
+
* ```
|
|
51
53
|
*/
|
|
52
54
|
filterInput(pred: (value: I, index: number, halt: () => void) => boolean): Reducer<I, O>;
|
|
53
55
|
/**
|
|
54
56
|
* Returns a `Reducer` instance that converts its input values using given `mapFun` before passing them to the reducer.
|
|
55
|
-
* @param mapFun - a function that returns a new value to pass to the reducer based on the following inputs
|
|
56
|
-
* - value: the current input value
|
|
57
|
+
* @param mapFun - a function that returns a new value to pass to the reducer based on the following inputs:<br/>
|
|
58
|
+
* - value: the current input value<br/>
|
|
57
59
|
* - index: the current input index
|
|
58
60
|
* @example
|
|
61
|
+
* ```ts
|
|
59
62
|
* Reducer.sum.mapInput(v => v * 2)
|
|
60
63
|
* // this reducer will double all input values before summing them
|
|
64
|
+
* ```
|
|
61
65
|
*/
|
|
62
66
|
mapInput<I2>(mapFun: (value: I2, index: number) => I): Reducer<I2, O>;
|
|
63
67
|
/**
|
|
64
68
|
* Returns a `Reducer` instance that converts or filters its input values using given `collectFun` before passing them to the reducer.
|
|
65
|
-
* @param collectFun - a function receiving
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
69
|
+
* @param collectFun - a function receiving<br/>
|
|
70
|
+
* - `value`: the next value<br/>
|
|
71
|
+
* - `index`: the value index<br/>
|
|
72
|
+
* - `skip`: a token that, when returned, will not add a value to the resulting collection<br/>
|
|
73
|
+
* - `halt`: a function that, when called, ensures no next elements are passed
|
|
70
74
|
* @example
|
|
75
|
+
* ```ts
|
|
71
76
|
* Reducer.sum.collectInput((v, _, skip) => v <= 10 ? skip : v * 2)
|
|
72
77
|
* // this reducer will double all input values larger thant 10 before summing them,
|
|
73
78
|
* // and will skip all values smaller than 10
|
|
79
|
+
* ```
|
|
74
80
|
*/
|
|
75
81
|
collectInput<I2>(collectFun: CollectFun<I2, I>): Reducer<I2, O>;
|
|
76
82
|
/**
|
|
77
83
|
* Returns a `Reducer` instance that converts its output values using given `mapFun`.
|
|
78
84
|
* @param mapFun - a function that takes the current output value and converts it to a new output value
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
79
87
|
* Reducer.sum.mapOutput(String)
|
|
80
88
|
* // this reducer will convert all its results to string before returning them
|
|
89
|
+
* ```
|
|
81
90
|
*/
|
|
82
91
|
mapOutput<O2>(mapFun: (value: O) => O2): Reducer<I, O2>;
|
|
83
92
|
/**
|
|
84
93
|
* Returns a `Reducer` instance that takes at most the given `amount` of input elements, and will ignore subsequent elements.
|
|
85
94
|
* @param amount - the amount of elements to accept
|
|
86
95
|
* @example
|
|
96
|
+
* ```ts
|
|
87
97
|
* Stream.range({ end: 10 }).reduce(Reducer.sum.takeInput(2))
|
|
88
98
|
* // => 1
|
|
99
|
+
* ```
|
|
89
100
|
*/
|
|
90
101
|
takeInput(amount: number): Reducer<I, O>;
|
|
91
102
|
/**
|
|
92
103
|
* Returns a `Reducer` instance that skips the first given `amount` of input elements, and will process subsequent elements.
|
|
93
104
|
* @param amount - the amount of elements to skip
|
|
94
105
|
* @example
|
|
106
|
+
* ```ts
|
|
95
107
|
* Stream.range({ end: 10 }).reduce(Reducer.sum.dropInput(9))
|
|
96
108
|
* // => 19
|
|
109
|
+
* ```
|
|
97
110
|
*/
|
|
98
111
|
dropInput(amount: number): Reducer<I, O>;
|
|
99
112
|
/**
|
|
@@ -101,8 +114,10 @@ export declare namespace Reducer {
|
|
|
101
114
|
* @param from - (default: 0) the index at which to start processing elements
|
|
102
115
|
* @param amount - (optional) the amount of elements to process, if not given, processes all elements from the `from` index
|
|
103
116
|
* @example
|
|
117
|
+
* ```ts
|
|
104
118
|
* Stream.range({ end: 10 }).reduce(Reducer.sum.sliceInput(1, 2))
|
|
105
119
|
* // => 3
|
|
120
|
+
* ```
|
|
106
121
|
*/
|
|
107
122
|
sliceInput(from?: number, amount?: number): Reducer<I, O>;
|
|
108
123
|
}
|
|
@@ -128,16 +143,17 @@ export declare namespace Reducer {
|
|
|
128
143
|
/**
|
|
129
144
|
* Returns a `Reducer` with the given options:
|
|
130
145
|
* @param init - the initial state value
|
|
131
|
-
* @param next - returns the next state value based on the given inputs
|
|
132
|
-
* - current: the current state
|
|
133
|
-
* - next: the current input value
|
|
134
|
-
* - index: the input index value
|
|
146
|
+
* @param next - returns the next state value based on the given inputs:<br/>
|
|
147
|
+
* - current: the current state<br/>
|
|
148
|
+
* - next: the current input value<br/>
|
|
149
|
+
* - index: the input index value<br/>
|
|
135
150
|
* - halt: function that, when called, ensures no more elements are passed to the reducer
|
|
136
151
|
* @param stateToResult - a function that converts the current state to an output value
|
|
137
152
|
* @typeparam I - the input value type
|
|
138
153
|
* @typeparam O - the output value type
|
|
139
154
|
* @typeparam S - the internal state type
|
|
140
155
|
* @example
|
|
156
|
+
* ```ts
|
|
141
157
|
* const evenNumberOfOnes = Reducer
|
|
142
158
|
* .create(
|
|
143
159
|
* true,
|
|
@@ -146,18 +162,21 @@ export declare namespace Reducer {
|
|
|
146
162
|
* const result = Stream.of(1, 2, 3, 2, 1)).reduce(evenNumberOfOnes)
|
|
147
163
|
* console.log+(result)
|
|
148
164
|
* // => 'even'
|
|
165
|
+
* ```
|
|
149
166
|
*/
|
|
150
167
|
function create<I, O = I, S = O>(init: Reducer.Init<S>, next: (current: S, next: I, index: number, halt: () => void) => S, stateToResult: (state: S) => O): Reducer<I, O>;
|
|
151
168
|
/**
|
|
152
169
|
* Returns a `Reducer` of which the input, state, and output types are the same.
|
|
153
170
|
* @param init - the initial state value
|
|
154
|
-
* @param next - returns the next state value based on the given inputs
|
|
155
|
-
* - current: the current state
|
|
156
|
-
* - next: the current input value
|
|
157
|
-
* - index: the input index value
|
|
171
|
+
* @param next - returns the next state value based on the given inputs:<br/>
|
|
172
|
+
* - current: the current state<br/>
|
|
173
|
+
* - next: the current input value<br/>
|
|
174
|
+
* - index: the input index value<br/>
|
|
158
175
|
* - halt: function that, when called, ensures no more elements are passed to the reducer
|
|
159
176
|
* @param stateToResult - (optional) a function that converts the current state to an output value
|
|
160
177
|
* @typeparam T - the overall value type
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
161
180
|
* const sum = Reducer
|
|
162
181
|
* .createMono(
|
|
163
182
|
* 0,
|
|
@@ -166,19 +185,22 @@ export declare namespace Reducer {
|
|
|
166
185
|
* const result = Stream.of(1, 2, 3, 2, 1)).reduce(sum)
|
|
167
186
|
* console.log+(result)
|
|
168
187
|
* // => 9
|
|
188
|
+
* ```
|
|
169
189
|
*/
|
|
170
190
|
function createMono<T>(init: Reducer.Init<T>, next: (current: T, next: T, index: number, halt: () => void) => T, stateToResult?: (state: T) => T): Reducer<T>;
|
|
171
191
|
/**
|
|
172
192
|
* Returns a `Reducer` of which the state and output types are the same.
|
|
173
193
|
* @param init - the initial state value
|
|
174
|
-
* @param next - returns the next state value based on the given inputs
|
|
175
|
-
* - current: the current state
|
|
176
|
-
* - next: the current input value
|
|
177
|
-
* - index: the input index value
|
|
194
|
+
* @param next - returns the next state value based on the given inputs:<br/>
|
|
195
|
+
* - current: the current state<br/>
|
|
196
|
+
* - next: the current input value<br/>
|
|
197
|
+
* - index: the input index value<br/>
|
|
178
198
|
* - halt: function that, when called, ensures no more elements are passed to the reducer
|
|
179
199
|
* @param stateToResult - (optional) a function that converts the current state to an output value
|
|
180
200
|
* @typeparam I - the input value type
|
|
181
201
|
* @typeparam O - the output value type
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
182
204
|
* const boolToString = Reducer
|
|
183
205
|
* .createOutput(
|
|
184
206
|
* '',
|
|
@@ -187,27 +209,34 @@ export declare namespace Reducer {
|
|
|
187
209
|
* const result = Stream.of(true, false, true)).reduce(boolToString)
|
|
188
210
|
* console.log+(result)
|
|
189
211
|
* // => 'TFT'
|
|
212
|
+
* ```
|
|
190
213
|
*/
|
|
191
214
|
function createOutput<I, O = I>(init: Reducer.Init<O>, next: (current: O, next: I, index: number, halt: () => void) => O, stateToResult?: (state: O) => O): Reducer<I, O>;
|
|
192
215
|
/**
|
|
193
216
|
* A `Reducer` that sums all given numeric input values.
|
|
194
217
|
* @example
|
|
218
|
+
* ```ts
|
|
195
219
|
* console.log(Stream.range({ amount: 5 }).reduce(Reducer.sum))
|
|
196
220
|
* // => 10
|
|
221
|
+
* ```
|
|
197
222
|
*/
|
|
198
223
|
const sum: Reducer<number, number>;
|
|
199
224
|
/**
|
|
200
225
|
* A `Reducer` that calculates the product of all given numeric input values.
|
|
201
226
|
* @example
|
|
227
|
+
* ```ts
|
|
202
228
|
* console.log(Stream.range({ start: 1, amount: 5 }).reduce(product))
|
|
203
229
|
* // => 120
|
|
230
|
+
* ```
|
|
204
231
|
*/
|
|
205
232
|
const product: Reducer<number, number>;
|
|
206
233
|
/**
|
|
207
234
|
* A `Reducer` that calculates the average of all given numberic input values.
|
|
208
235
|
* @example
|
|
236
|
+
* ```ts
|
|
209
237
|
* console.log(Stream.range({ amount: 5 }).reduce(Reducer.average));
|
|
210
238
|
* // => 2
|
|
239
|
+
* ```
|
|
211
240
|
*/
|
|
212
241
|
const average: Reducer<number, number>;
|
|
213
242
|
/**
|
|
@@ -215,9 +244,11 @@ export declare namespace Reducer {
|
|
|
215
244
|
* @param compFun - a comparison function for two input values, returning 0 when equal, positive when greater, negetive when smaller
|
|
216
245
|
* @param otherwise - (default: undefineds) a fallback value when there were no input values given
|
|
217
246
|
* @example
|
|
247
|
+
* ```ts
|
|
218
248
|
* const stream = Stream.of('abc', 'a', 'abcde', 'ab')
|
|
219
249
|
* console.log(stream.minBy((s1, s2) => s1.length - s2.length))
|
|
220
250
|
* // 'a'
|
|
251
|
+
* ```
|
|
221
252
|
*/
|
|
222
253
|
const minBy: {
|
|
223
254
|
<T>(compFun: (v1: T, v2: T) => number): Reducer<T, T | undefined>;
|
|
@@ -227,8 +258,10 @@ export declare namespace Reducer {
|
|
|
227
258
|
* Returns a `Reducer` that remembers the minimum value of the numberic inputs.
|
|
228
259
|
* @param otherwise - (default: undefined) a fallback value when there were no input values given
|
|
229
260
|
* @example
|
|
261
|
+
* ```ts
|
|
230
262
|
* console.log(Stream.of(5, 3, 7, 4).reduce(Reducer.min()))
|
|
231
263
|
* // => 3
|
|
264
|
+
* ```
|
|
232
265
|
*/
|
|
233
266
|
const min: {
|
|
234
267
|
(): Reducer<number, number | undefined>;
|
|
@@ -239,9 +272,11 @@ export declare namespace Reducer {
|
|
|
239
272
|
* @param compFun - a comparison function for two input values, returning 0 when equal, positive when greater, negetive when smaller
|
|
240
273
|
* @param otherwise - (default: undefined) a fallback value when there were no input values given
|
|
241
274
|
* @example
|
|
275
|
+
* ```ts
|
|
242
276
|
* const stream = Stream.of('abc', 'a', 'abcde', 'ab')
|
|
243
277
|
* console.log(stream.maxBy((s1, s2) => s1.length - s2.length))
|
|
244
278
|
* // 'abcde'
|
|
279
|
+
* ```
|
|
245
280
|
*/
|
|
246
281
|
const maxBy: {
|
|
247
282
|
<T>(compFun: (v1: T, v2: T) => number): Reducer<T, T | undefined>;
|
|
@@ -251,22 +286,26 @@ export declare namespace Reducer {
|
|
|
251
286
|
* Returns a `Reducer` that remembers the maximum value of the numberic inputs.
|
|
252
287
|
* @param otherwise - (default: undefined) a fallback value when there were no input values given
|
|
253
288
|
* @example
|
|
289
|
+
* ```ts
|
|
254
290
|
* console.log(Stream.of(5, 3, 7, 4).reduce(Reducer.max()))
|
|
255
291
|
* // => 7
|
|
292
|
+
* ```
|
|
256
293
|
*/
|
|
257
294
|
const max: {
|
|
258
295
|
(): Reducer<number, number | undefined>;
|
|
259
296
|
<O>(otherwise: OptLazy<O>): Reducer<number, number | O>;
|
|
260
297
|
};
|
|
261
298
|
/**
|
|
262
|
-
* Returns a `
|
|
263
|
-
* @options - an object containing
|
|
264
|
-
* - sep: (optional) a seperator string value between values in the output
|
|
265
|
-
* - start: (optional) a start string to prepend to the output
|
|
266
|
-
* - end: (optional) an end string to append to the output
|
|
299
|
+
* Returns a `yaReducer` that joins the given input values into a string using the given options.
|
|
300
|
+
* @param options - an object containing:<br/>
|
|
301
|
+
* - sep: (optional) a seperator string value between values in the output<br/>
|
|
302
|
+
* - start: (optional) a start string to prepend to the output<br/>
|
|
303
|
+
* - end: (optional) an end string to append to the output<br/>
|
|
267
304
|
* @example
|
|
305
|
+
* ```ts
|
|
268
306
|
* console.log(Stream.of(1, 2, 3).reduce(Reducer.join({ sep: '-' })))
|
|
269
307
|
* // => '1-2-3'
|
|
308
|
+
* ```
|
|
270
309
|
*/
|
|
271
310
|
function join<T>({ sep, start, end, valueToString, }?: {
|
|
272
311
|
sep?: string | undefined;
|
|
@@ -276,15 +315,17 @@ export declare namespace Reducer {
|
|
|
276
315
|
}): Reducer<T, string>;
|
|
277
316
|
/**
|
|
278
317
|
* Returns a `Reducer` that remembers the amount of input items provided.
|
|
279
|
-
* @param pred - (optional) a predicate that returns false if the item should not be counted given
|
|
280
|
-
* - value: the current input value
|
|
318
|
+
* @param pred - (optional) a predicate that returns false if the item should not be counted given:<br/>
|
|
319
|
+
* - value: the current input value<br/>
|
|
281
320
|
* - index: the input value index
|
|
282
321
|
* @example
|
|
322
|
+
* ```ts
|
|
283
323
|
* const stream = Stream.range({ amount: 10 })
|
|
284
324
|
* console.log(stream.reduce(Reducer.count()))
|
|
285
325
|
* // => 10
|
|
286
326
|
* console.log(stream.reduce(Reducer.count(v => v < 5)))
|
|
287
327
|
* // => 5
|
|
328
|
+
* ```
|
|
288
329
|
*/
|
|
289
330
|
const count: {
|
|
290
331
|
(): Reducer<any, number>;
|
|
@@ -297,8 +338,10 @@ export declare namespace Reducer {
|
|
|
297
338
|
* @typeparam T - the input value type
|
|
298
339
|
* @typeparam O - the fallback value type
|
|
299
340
|
* @example
|
|
341
|
+
* ```ts
|
|
300
342
|
* console.log(Stream.range({ amount: 10 }).reduce(Reducer.firstWhere(v => v > 5)))
|
|
301
343
|
* // => 6
|
|
344
|
+
* ```
|
|
302
345
|
*/
|
|
303
346
|
const firstWhere: {
|
|
304
347
|
<T>(pred: (value: T, index: number) => boolean): Reducer<T, T | undefined>;
|
|
@@ -310,8 +353,10 @@ export declare namespace Reducer {
|
|
|
310
353
|
* @typeparam T - the input value type
|
|
311
354
|
* @typeparam O - the fallback value type
|
|
312
355
|
* @example
|
|
356
|
+
* ```ts
|
|
313
357
|
* console.log(Stream.range{ amount: 10 }).reduce(Reducer.first())
|
|
314
358
|
* // => 0
|
|
359
|
+
* ```
|
|
315
360
|
*/
|
|
316
361
|
const first: {
|
|
317
362
|
<T>(): Reducer<T, T | undefined>;
|
|
@@ -324,8 +369,10 @@ export declare namespace Reducer {
|
|
|
324
369
|
* @typeparam T - the input value type
|
|
325
370
|
* @typeparam O - the fallback value type
|
|
326
371
|
* @example
|
|
372
|
+
* ```ts
|
|
327
373
|
* console.log(Stream.range({ amount: 10 }).reduce(Reducer.lastWhere(v => v > 5)))
|
|
328
374
|
* // => 9
|
|
375
|
+
* ```
|
|
329
376
|
*/
|
|
330
377
|
const lastWhere: {
|
|
331
378
|
<T>(pred: (value: T, index: number) => boolean): Reducer<T, T | undefined>;
|
|
@@ -337,8 +384,10 @@ export declare namespace Reducer {
|
|
|
337
384
|
* @typeparam T - the input value type
|
|
338
385
|
* @typeparam O - the fallback value type
|
|
339
386
|
* @example
|
|
387
|
+
* ```ts
|
|
340
388
|
* console.log(Stream.range{ amount: 10 }).reduce(Reducer.first())
|
|
341
389
|
* // => 0
|
|
390
|
+
* ```
|
|
342
391
|
*/
|
|
343
392
|
const last: {
|
|
344
393
|
<T>(): Reducer<T, T | undefined>;
|
|
@@ -348,16 +397,20 @@ export declare namespace Reducer {
|
|
|
348
397
|
* Returns a `Reducer` that ouputs false as long as no input value satisfies given `pred`, true otherwise.
|
|
349
398
|
* @param pred - a function taking an input value and its index, and returning true if the value satisfies the predicate
|
|
350
399
|
* @example
|
|
400
|
+
* ```ts
|
|
351
401
|
* console.log(Stream.range{ amount: 10 }).reduce(Reducer.some(v => v > 5))
|
|
352
402
|
* // => true
|
|
403
|
+
* ```
|
|
353
404
|
*/
|
|
354
405
|
function some<T>(pred: (value: T, index: number) => boolean): Reducer<T, boolean>;
|
|
355
406
|
/**
|
|
356
407
|
* Returns a `Reducer` that ouputs true as long as all input values satisfy the given `pred`, false otherwise.
|
|
357
408
|
* @param pred - a function taking an input value and its index, and returning true if the value satisfies the predicate
|
|
358
409
|
* @example
|
|
410
|
+
* ```ts
|
|
359
411
|
* console.log(Stream.range{ amount: 10 }).reduce(Reducer.every(v => v < 5))
|
|
360
412
|
* // => false
|
|
413
|
+
* ```
|
|
361
414
|
*/
|
|
362
415
|
function every<T>(pred: (value: T, index: number) => boolean): Reducer<T, boolean>;
|
|
363
416
|
/**
|
|
@@ -365,68 +418,86 @@ export declare namespace Reducer {
|
|
|
365
418
|
* @param elem - the element to search for
|
|
366
419
|
* @param eq - (optional) a comparison function that returns true if te two given input values are considered equal
|
|
367
420
|
* @example
|
|
421
|
+
* ```ts
|
|
368
422
|
* console.log(Stream.range({ amount: 10 }).reduce(Reducer.contains(5)))
|
|
369
423
|
* // => true
|
|
424
|
+
* ```
|
|
370
425
|
*/
|
|
371
426
|
function contains<T>(elem: T, eq?: Eq<T>): Reducer<T, boolean>;
|
|
372
427
|
/**
|
|
373
428
|
* Returns a `Reducer` that takes boolean values and outputs true if all input values are true, and false otherwise.
|
|
374
429
|
* @example
|
|
430
|
+
* ```ts
|
|
375
431
|
* console.log(Stream.of(true, false, true)).reduce(Reducer.and))
|
|
376
432
|
* // => false
|
|
433
|
+
* ```
|
|
377
434
|
*/
|
|
378
435
|
const and: Reducer<boolean, boolean>;
|
|
379
436
|
/**
|
|
380
437
|
* Returns a `Reducer` that takes boolean values and outputs true if one or more input values are true, and false otherwise.
|
|
381
438
|
* @example
|
|
439
|
+
* ```ts
|
|
382
440
|
* console.log(Stream.of(true, false, true)).reduce(Reducer.or))
|
|
383
441
|
* // => true
|
|
442
|
+
* ```
|
|
384
443
|
*/
|
|
385
444
|
const or: Reducer<boolean, boolean>;
|
|
386
445
|
/**
|
|
387
446
|
* Returns a `Reducer` that outputs true if no input values are received, false otherwise.
|
|
388
447
|
* @example
|
|
448
|
+
* ```ts
|
|
389
449
|
* console.log(Stream.of(1, 2, 3).reduce(Reducer.isEmpty))
|
|
390
450
|
* // => false
|
|
451
|
+
* ```
|
|
391
452
|
*/
|
|
392
453
|
const isEmpty: Reducer<any, boolean>;
|
|
393
454
|
/**
|
|
394
455
|
* Returns a `Reducer` that outputs true if one or more input values are received, false otherwise.
|
|
395
456
|
* @example
|
|
457
|
+
* ```ts
|
|
396
458
|
* console.log(Stream.of(1, 2, 3).reduce(Reducer.nonEmpty))
|
|
397
459
|
* // => true
|
|
460
|
+
* ```
|
|
398
461
|
*/
|
|
399
462
|
const nonEmpty: Reducer<any, boolean>;
|
|
400
463
|
/**
|
|
401
464
|
* Returns a `Reducer` that collects received input values in an array, and returns a copy of that array as an output value when requested.
|
|
402
465
|
* @example
|
|
466
|
+
* ```ts
|
|
403
467
|
* console.log(Stream.of(1, 2, 3).reduce(Reducer.toArray()))
|
|
404
468
|
* // => [1, 2, 3]
|
|
469
|
+
* ```
|
|
405
470
|
*/
|
|
406
471
|
function toArray<T>(): Reducer<T, T[]>;
|
|
407
472
|
/**
|
|
408
473
|
* Returns a `Reducer` that collects received input tuples into a mutable JS Map, and returns
|
|
409
474
|
* a copy of that map when output is requested.
|
|
410
475
|
* @example
|
|
476
|
+
* ```ts
|
|
411
477
|
* console.log(Stream.of([1, 'a'], [2, 'b']).reduce(Reducer.toJSMap()))
|
|
412
478
|
* // Map { 1 => 'a', 2 => 'b' }
|
|
479
|
+
* ```
|
|
413
480
|
*/
|
|
414
481
|
function toJSMap<K, V>(): Reducer<[K, V], Map<K, V>>;
|
|
415
482
|
/**
|
|
416
483
|
* Returns a `Reducer` that collects received input values into a mutable JS Set, and returns
|
|
417
484
|
* a copy of that map when output is requested.
|
|
418
485
|
* @example
|
|
486
|
+
* ```ts
|
|
419
487
|
* console.log(Stream.of(1, 2, 3).reduce(Reducer.toJSSet()))
|
|
420
488
|
* // Set {1, 2, 3}
|
|
489
|
+
* ```
|
|
421
490
|
*/
|
|
422
491
|
function toJSSet<T>(): Reducer<T, Set<T>>;
|
|
423
492
|
/**
|
|
424
493
|
* Returns a `Reducer` that combines multiple input `reducers` by providing input values to all of them and collecting the outputs in an array.
|
|
425
494
|
* @param reducers - 2 or more reducers to combine
|
|
426
495
|
* @example
|
|
496
|
+
* ```ts
|
|
427
497
|
* const red = Reducer.combine(Reducer.sum, Reducer.average)
|
|
428
498
|
* console.log(Stream.range({amount: 9 }).reduce(red))
|
|
429
499
|
* // => [36, 4]
|
|
500
|
+
* ```
|
|
430
501
|
*/
|
|
431
502
|
function combine<T, R extends readonly [unknown, unknown, ...unknown[]]>(...reducers: {
|
|
432
503
|
[K in keyof R]: Reducer<T, R[K]>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -20,10 +20,6 @@ export declare type ArrayNonEmpty<T> = [T, ...T[]];
|
|
|
20
20
|
* Accepts all strings with at least one character.
|
|
21
21
|
*/
|
|
22
22
|
export declare type StringNonEmpty<T> = T extends string ? '' extends T ? never : T : never;
|
|
23
|
-
/**
|
|
24
|
-
* A stronger version of `Omit`, which only accepts keys that are in type T.
|
|
25
|
-
*/
|
|
26
|
-
export declare type OmitStrong<T, K extends keyof T> = Omit<T, K>;
|
|
27
23
|
/**
|
|
28
24
|
* Utility type to convert some object to a JSON serializable format.
|
|
29
25
|
* @typeparam V - the `value` type
|
package/dist/types/update.d.ts
CHANGED
|
@@ -5,12 +5,14 @@ export declare type Update<T> = T | ((value: T) => T);
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns the result of given `update` parameter, where it can either directly give a new value,
|
|
7
7
|
* or it is a function receiving the given `value`, and returns a new value.
|
|
8
|
-
* @param value - the current
|
|
8
|
+
* @param value - the current value
|
|
9
9
|
* @param update - an `Update` value, either a new value or a function receiving the old value
|
|
10
10
|
* and returning a new one.
|
|
11
11
|
* @example
|
|
12
|
+
* ```ts
|
|
12
13
|
* Update(1, 2) // => 2
|
|
13
14
|
* Update(1, () => 10) // => 10
|
|
14
15
|
* Update(1, v => v + 1) // => 2
|
|
16
|
+
* ```
|
|
15
17
|
*/
|
|
16
18
|
export declare function Update<T>(value: T, update: Update<T>): T;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimbu/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "Common types and objects used in many other Rimbu packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"common",
|
|
@@ -38,12 +38,13 @@
|
|
|
38
38
|
],
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "yarn clean && yarn bundle",
|
|
41
|
-
"build:deno": "rimraf deno_dist ../../deno_dist/common && denoify &&
|
|
41
|
+
"build:deno": "rimraf deno_dist ../../deno_dist/common && denoify && mv deno_dist ../../deno_dist/common",
|
|
42
42
|
"bundle": "yarn bundle:main && yarn bundle:module && yarn bundle:types",
|
|
43
43
|
"bundle:main": "tsc --p tsconfig.main.json",
|
|
44
44
|
"bundle:module": "tsc --p tsconfig.module.json",
|
|
45
45
|
"bundle:types": "tsc --p tsconfig.types.json",
|
|
46
46
|
"clean": "rimraf dist",
|
|
47
|
+
"extract-api": "api-extractor run --local --verbose",
|
|
47
48
|
"format": "yarn format:base --write",
|
|
48
49
|
"format:base": "prettier \"{!CHANGELOG.md}|**/**/*.{ts,tsx,js,json,md}\"",
|
|
49
50
|
"format:check": "yarn format:base --check",
|
|
@@ -56,10 +57,11 @@
|
|
|
56
57
|
"access": "public"
|
|
57
58
|
},
|
|
58
59
|
"denoify": {
|
|
60
|
+
"index": "src/index.ts",
|
|
59
61
|
"replacer": "../../config/denoify-rimbu-replacer.js"
|
|
60
62
|
},
|
|
61
63
|
"dependencies": {
|
|
62
|
-
"tslib": "^2.
|
|
64
|
+
"tslib": "^2.4.0"
|
|
63
65
|
},
|
|
64
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "33dd7ca935f19f513586834a2ce1b1f886352ae7"
|
|
65
67
|
}
|
package/src/async-optlazy.ts
CHANGED
|
@@ -17,11 +17,13 @@ export namespace AsyncOptLazy {
|
|
|
17
17
|
* Returns the value or promised value contained in an `AsyncOptLazy` instance of type T.
|
|
18
18
|
* @param optLazy - the `AsyncOptLazy` value of type T
|
|
19
19
|
* @example
|
|
20
|
+
* ```ts
|
|
20
21
|
* AsyncOptLazy.toMaybePromise(1) // => 1
|
|
21
22
|
* AsyncOptLazy.toMaybePromise(() => 1) // => 1
|
|
22
23
|
* AsyncOptLazy.toMaybePromise(() => () => 1) // => () => 1
|
|
23
24
|
* AsyncOptLazy.toMaybePromise(async () => 1) // => Promise(1)
|
|
24
25
|
* AsyncOptLazy.toMaybePromise(Promise.resolve(1)) // => Promise(1)
|
|
26
|
+
* ```
|
|
25
27
|
*/
|
|
26
28
|
export function toMaybePromise<T>(optLazy: AsyncOptLazy<T>): MaybePromise<T> {
|
|
27
29
|
if (optLazy instanceof Function) return optLazy();
|
|
@@ -32,11 +34,13 @@ export namespace AsyncOptLazy {
|
|
|
32
34
|
* Returns the value contained in an `AsyncOptLazy` instance of type T as a promise.
|
|
33
35
|
* @param optLazy - the `AsyncOptLazy` value of type T
|
|
34
36
|
* @example
|
|
37
|
+
* ```ts
|
|
35
38
|
* AsyncOptLazy.toPromise(1) // => Promise(1)
|
|
36
39
|
* AsyncOptLazy.toPromise(() => 1) // => Promise(1)
|
|
37
40
|
* AsyncOptLazy.toPromise(() => () => 1) // => Promise(() => 1)
|
|
38
41
|
* AsyncOptLazy.toPromise(async () => 1) // => Promise(1)
|
|
39
42
|
* AsyncOptLazy.toPromise(Promise.resolve(1)) // => Promise(1)
|
|
43
|
+
* ```
|
|
40
44
|
*/
|
|
41
45
|
export async function toPromise<T>(optLazy: AsyncOptLazy<T>): Promise<T> {
|
|
42
46
|
if (optLazy instanceof Function) return optLazy();
|