rubico 2.6.5 → 2.7.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/Transducer.d.ts +1 -1
- package/Transducer.js +65 -16
- package/__.js +10 -1
- package/all.d.ts +2 -2
- package/all.js +11 -2
- package/always.js +8 -0
- package/and.js +6 -0
- package/assign.js +9 -0
- package/compose.js +33 -8
- package/curry.js +18 -0
- package/dist/Transducer.es.js +2 -2
- package/dist/Transducer.es.min.js +2 -2
- package/dist/Transducer.js +2 -2
- package/dist/Transducer.min.js +2 -2
- package/dist/Transducer.mjs +2 -2
- package/dist/__.es.js +2 -2
- package/dist/__.es.min.js +2 -2
- package/dist/__.js +2 -2
- package/dist/__.min.js +2 -2
- package/dist/__.mjs +2 -2
- package/dist/all.es.js +2 -22
- package/dist/all.es.min.js +2 -2
- package/dist/all.js +2 -22
- package/dist/all.min.js +2 -2
- package/dist/all.mjs +2 -22
- package/dist/always.es.js +2 -2
- package/dist/always.es.min.js +2 -2
- package/dist/always.js +2 -2
- package/dist/always.min.js +2 -2
- package/dist/always.mjs +2 -2
- package/dist/and.es.js +2 -2
- package/dist/and.es.min.js +2 -2
- package/dist/and.js +2 -2
- package/dist/and.min.js +2 -2
- package/dist/and.mjs +2 -2
- package/dist/assign.es.js +2 -2
- package/dist/assign.es.min.js +2 -2
- package/dist/assign.js +2 -2
- package/dist/assign.min.js +2 -2
- package/dist/assign.mjs +2 -2
- package/dist/compose.es.js +6 -2
- package/dist/compose.es.min.js +3 -3
- package/dist/compose.js +6 -2
- package/dist/compose.min.js +3 -3
- package/dist/compose.mjs +6 -2
- package/dist/curry.es.js +2 -2
- package/dist/curry.es.min.js +2 -2
- package/dist/curry.js +2 -2
- package/dist/curry.min.js +2 -2
- package/dist/curry.mjs +2 -2
- package/dist/eq.es.js +2 -2
- package/dist/eq.es.min.js +2 -2
- package/dist/eq.js +2 -2
- package/dist/eq.min.js +2 -2
- package/dist/eq.mjs +2 -2
- package/dist/every.es.js +2 -2
- package/dist/every.es.min.js +2 -2
- package/dist/every.js +2 -2
- package/dist/every.min.js +2 -2
- package/dist/every.mjs +2 -2
- package/dist/filter.es.js +5 -3
- package/dist/filter.es.min.js +3 -3
- package/dist/filter.js +5 -3
- package/dist/filter.min.js +3 -3
- package/dist/filter.mjs +5 -3
- package/dist/flatMap.es.js +2 -2
- package/dist/flatMap.es.min.js +2 -2
- package/dist/flatMap.js +2 -2
- package/dist/flatMap.min.js +2 -2
- package/dist/flatMap.mjs +2 -2
- package/dist/forEach.es.js +2 -2
- package/dist/forEach.es.min.js +2 -2
- package/dist/forEach.js +2 -2
- package/dist/forEach.min.js +2 -2
- package/dist/forEach.mjs +2 -2
- package/dist/get.es.js +2 -2
- package/dist/get.es.min.js +2 -2
- package/dist/get.js +2 -2
- package/dist/get.min.js +2 -2
- package/dist/get.mjs +2 -2
- package/dist/gt.es.js +2 -2
- package/dist/gt.es.min.js +2 -2
- package/dist/gt.js +2 -2
- package/dist/gt.min.js +2 -2
- package/dist/gt.mjs +2 -2
- package/dist/gte.es.js +2 -2
- package/dist/gte.es.min.js +2 -2
- package/dist/gte.js +2 -2
- package/dist/gte.min.js +2 -2
- package/dist/gte.mjs +2 -2
- package/dist/lt.es.js +2 -2
- package/dist/lt.es.min.js +2 -2
- package/dist/lt.js +2 -2
- package/dist/lt.min.js +2 -2
- package/dist/lt.mjs +2 -2
- package/dist/lte.es.js +2 -2
- package/dist/lte.es.min.js +2 -2
- package/dist/lte.js +2 -2
- package/dist/lte.min.js +2 -2
- package/dist/lte.mjs +2 -2
- package/dist/map.es.js +31 -31
- package/dist/map.es.min.js +3 -3
- package/dist/map.js +31 -31
- package/dist/map.min.js +3 -3
- package/dist/map.mjs +31 -31
- package/dist/not.es.js +2 -2
- package/dist/not.es.min.js +2 -2
- package/dist/not.js +2 -2
- package/dist/not.min.js +2 -2
- package/dist/not.mjs +2 -2
- package/dist/omit.es.js +2 -2
- package/dist/omit.es.min.js +2 -2
- package/dist/omit.js +2 -2
- package/dist/omit.min.js +2 -2
- package/dist/omit.mjs +2 -2
- package/dist/or.es.js +2 -2
- package/dist/or.es.min.js +2 -2
- package/dist/or.js +2 -2
- package/dist/or.min.js +2 -2
- package/dist/or.mjs +2 -2
- package/dist/pick.es.js +2 -2
- package/dist/pick.es.min.js +2 -2
- package/dist/pick.js +2 -2
- package/dist/pick.min.js +2 -2
- package/dist/pick.mjs +2 -2
- package/dist/pipe.es.js +6 -2
- package/dist/pipe.es.min.js +3 -3
- package/dist/pipe.js +6 -2
- package/dist/pipe.min.js +3 -3
- package/dist/pipe.mjs +6 -2
- package/dist/reduce.es.js +9 -9
- package/dist/reduce.es.min.js +2 -2
- package/dist/reduce.js +9 -9
- package/dist/reduce.min.js +2 -2
- package/dist/reduce.mjs +9 -9
- package/dist/rubico.es.js +49 -59
- package/dist/rubico.es.min.js +3 -3
- package/dist/rubico.global.js +49 -59
- package/dist/rubico.global.min.js +3 -3
- package/dist/rubico.js +49 -59
- package/dist/rubico.min.js +3 -3
- package/dist/rubico.mjs +49 -59
- package/dist/set.es.js +2 -2
- package/dist/set.es.min.js +2 -2
- package/dist/set.js +2 -2
- package/dist/set.min.js +2 -2
- package/dist/set.mjs +2 -2
- package/dist/some.es.js +2 -2
- package/dist/some.es.min.js +2 -2
- package/dist/some.js +2 -2
- package/dist/some.min.js +2 -2
- package/dist/some.mjs +2 -2
- package/dist/switchCase.es.js +2 -2
- package/dist/switchCase.es.min.js +2 -2
- package/dist/switchCase.js +2 -2
- package/dist/switchCase.min.js +2 -2
- package/dist/switchCase.mjs +2 -2
- package/dist/tap.es.js +2 -2
- package/dist/tap.es.min.js +2 -2
- package/dist/tap.js +2 -2
- package/dist/tap.min.js +2 -2
- package/dist/tap.mjs +2 -2
- package/dist/thunkify.es.js +2 -2
- package/dist/thunkify.es.min.js +2 -2
- package/dist/thunkify.js +2 -2
- package/dist/thunkify.min.js +2 -2
- package/dist/thunkify.mjs +2 -2
- package/dist/transform.es.js +2 -2
- package/dist/transform.es.min.js +2 -2
- package/dist/transform.js +2 -2
- package/dist/transform.min.js +2 -2
- package/dist/transform.mjs +2 -2
- package/dist/tryCatch.es.js +2 -2
- package/dist/tryCatch.es.min.js +2 -2
- package/dist/tryCatch.js +2 -2
- package/dist/tryCatch.min.js +2 -2
- package/dist/tryCatch.mjs +2 -2
- package/dist/x/append.es.js +2 -2
- package/dist/x/append.es.min.js +2 -2
- package/dist/x/append.js +2 -2
- package/dist/x/append.min.js +2 -2
- package/dist/x/append.mjs +2 -2
- package/dist/x/callProp.es.js +2 -2
- package/dist/x/callProp.es.min.js +2 -2
- package/dist/x/callProp.js +2 -2
- package/dist/x/callProp.min.js +2 -2
- package/dist/x/callProp.mjs +2 -2
- package/dist/x/defaultsDeep.es.js +2 -2
- package/dist/x/defaultsDeep.es.min.js +2 -2
- package/dist/x/defaultsDeep.js +2 -2
- package/dist/x/defaultsDeep.min.js +2 -2
- package/dist/x/defaultsDeep.mjs +2 -2
- package/dist/x/differenceWith.es.js +2 -2
- package/dist/x/differenceWith.es.min.js +2 -2
- package/dist/x/differenceWith.js +2 -2
- package/dist/x/differenceWith.min.js +2 -2
- package/dist/x/differenceWith.mjs +2 -2
- package/dist/x/filterOut.es.js +5 -3
- package/dist/x/filterOut.es.min.js +3 -3
- package/dist/x/filterOut.js +5 -3
- package/dist/x/filterOut.min.js +3 -3
- package/dist/x/filterOut.mjs +5 -3
- package/dist/x/find.es.js +2 -2
- package/dist/x/find.es.min.js +2 -2
- package/dist/x/find.js +2 -2
- package/dist/x/find.min.js +2 -2
- package/dist/x/find.mjs +2 -2
- package/dist/x/findIndex.es.js +2 -2
- package/dist/x/findIndex.es.min.js +2 -2
- package/dist/x/findIndex.js +2 -2
- package/dist/x/findIndex.min.js +2 -2
- package/dist/x/findIndex.mjs +2 -2
- package/dist/x/first.es.js +2 -2
- package/dist/x/first.es.min.js +2 -2
- package/dist/x/first.js +2 -2
- package/dist/x/first.min.js +2 -2
- package/dist/x/first.mjs +2 -2
- package/dist/x/flatten.es.js +2 -2
- package/dist/x/flatten.es.min.js +2 -2
- package/dist/x/flatten.js +2 -2
- package/dist/x/flatten.min.js +2 -2
- package/dist/x/flatten.mjs +2 -2
- package/dist/x/groupBy.es.js +9 -9
- package/dist/x/groupBy.es.min.js +2 -2
- package/dist/x/groupBy.js +9 -9
- package/dist/x/groupBy.min.js +2 -2
- package/dist/x/groupBy.mjs +9 -9
- package/dist/x/has.es.js +2 -2
- package/dist/x/has.es.min.js +2 -2
- package/dist/x/has.js +2 -2
- package/dist/x/has.min.js +2 -2
- package/dist/x/has.mjs +2 -2
- package/dist/x/identity.es.js +2 -2
- package/dist/x/identity.es.min.js +2 -2
- package/dist/x/identity.js +2 -2
- package/dist/x/identity.min.js +2 -2
- package/dist/x/identity.mjs +2 -2
- package/dist/x/includes.es.js +2 -2
- package/dist/x/includes.es.min.js +2 -2
- package/dist/x/includes.js +2 -2
- package/dist/x/includes.min.js +2 -2
- package/dist/x/includes.mjs +2 -2
- package/dist/x/isDeepEqual.es.js +2 -2
- package/dist/x/isDeepEqual.es.min.js +2 -2
- package/dist/x/isDeepEqual.js +2 -2
- package/dist/x/isDeepEqual.min.js +2 -2
- package/dist/x/isDeepEqual.mjs +2 -2
- package/dist/x/isEmpty.es.js +2 -2
- package/dist/x/isEmpty.es.min.js +2 -2
- package/dist/x/isEmpty.js +2 -2
- package/dist/x/isEmpty.min.js +2 -2
- package/dist/x/isEmpty.mjs +2 -2
- package/dist/x/isEqual.es.js +2 -2
- package/dist/x/isEqual.es.min.js +2 -2
- package/dist/x/isEqual.js +2 -2
- package/dist/x/isEqual.min.js +2 -2
- package/dist/x/isEqual.mjs +2 -2
- package/dist/x/isFunction.es.js +2 -2
- package/dist/x/isFunction.es.min.js +2 -2
- package/dist/x/isFunction.js +2 -2
- package/dist/x/isFunction.min.js +2 -2
- package/dist/x/isFunction.mjs +2 -2
- package/dist/x/isIn.es.js +2 -2
- package/dist/x/isIn.es.min.js +2 -2
- package/dist/x/isIn.js +2 -2
- package/dist/x/isIn.min.js +2 -2
- package/dist/x/isIn.mjs +2 -2
- package/dist/x/isObject.es.js +2 -2
- package/dist/x/isObject.es.min.js +2 -2
- package/dist/x/isObject.js +2 -2
- package/dist/x/isObject.min.js +2 -2
- package/dist/x/isObject.mjs +2 -2
- package/dist/x/isString.es.js +2 -2
- package/dist/x/isString.es.min.js +2 -2
- package/dist/x/isString.js +2 -2
- package/dist/x/isString.min.js +2 -2
- package/dist/x/isString.mjs +2 -2
- package/dist/x/keys.es.js +2 -2
- package/dist/x/keys.es.min.js +2 -2
- package/dist/x/keys.js +2 -2
- package/dist/x/keys.min.js +2 -2
- package/dist/x/keys.mjs +2 -2
- package/dist/x/last.es.js +2 -2
- package/dist/x/last.es.min.js +2 -2
- package/dist/x/last.js +2 -2
- package/dist/x/last.min.js +2 -2
- package/dist/x/last.mjs +2 -2
- package/dist/x/maxBy.es.js +2 -2
- package/dist/x/maxBy.es.min.js +2 -2
- package/dist/x/maxBy.js +2 -2
- package/dist/x/maxBy.min.js +2 -2
- package/dist/x/maxBy.mjs +2 -2
- package/dist/x/noop.es.js +2 -2
- package/dist/x/noop.es.min.js +2 -2
- package/dist/x/noop.js +2 -2
- package/dist/x/noop.min.js +2 -2
- package/dist/x/noop.mjs +2 -2
- package/dist/x/pluck.es.js +31 -31
- package/dist/x/pluck.es.min.js +3 -3
- package/dist/x/pluck.js +31 -31
- package/dist/x/pluck.min.js +3 -3
- package/dist/x/pluck.mjs +31 -31
- package/dist/x/prepend.es.js +2 -2
- package/dist/x/prepend.es.min.js +2 -2
- package/dist/x/prepend.js +2 -2
- package/dist/x/prepend.min.js +2 -2
- package/dist/x/prepend.mjs +2 -2
- package/dist/x/size.es.js +2 -2
- package/dist/x/size.es.min.js +2 -2
- package/dist/x/size.js +2 -2
- package/dist/x/size.min.js +2 -2
- package/dist/x/size.mjs +2 -2
- package/dist/x/trace.es.js +2 -2
- package/dist/x/trace.es.min.js +2 -2
- package/dist/x/trace.js +2 -2
- package/dist/x/trace.min.js +2 -2
- package/dist/x/trace.mjs +2 -2
- package/dist/x/unionWith.es.js +2 -2
- package/dist/x/unionWith.es.min.js +2 -2
- package/dist/x/unionWith.js +2 -2
- package/dist/x/unionWith.min.js +2 -2
- package/dist/x/unionWith.mjs +2 -2
- package/dist/x/uniq.es.js +2 -2
- package/dist/x/uniq.es.min.js +2 -2
- package/dist/x/uniq.js +2 -2
- package/dist/x/uniq.min.js +2 -2
- package/dist/x/uniq.mjs +2 -2
- package/dist/x/unless.es.js +2 -2
- package/dist/x/unless.es.min.js +2 -2
- package/dist/x/unless.js +2 -2
- package/dist/x/unless.min.js +2 -2
- package/dist/x/unless.mjs +2 -2
- package/dist/x/values.es.js +2 -2
- package/dist/x/values.es.min.js +2 -2
- package/dist/x/values.js +2 -2
- package/dist/x/values.min.js +2 -2
- package/dist/x/values.mjs +2 -2
- package/dist/x/when.es.js +2 -2
- package/dist/x/when.es.min.js +2 -2
- package/dist/x/when.js +2 -2
- package/dist/x/when.min.js +2 -2
- package/dist/x/when.mjs +2 -2
- package/eq.d.ts +6 -6
- package/eq.js +14 -6
- package/es.js +49 -59
- package/every.js +19 -5
- package/filter.js +87 -47
- package/flatMap.js +38 -32
- package/forEach.js +107 -13
- package/get.js +9 -0
- package/gt.js +9 -0
- package/gte.js +9 -0
- package/index.js +49 -59
- package/lte.js +9 -0
- package/map.js +198 -103
- package/not.js +7 -0
- package/omit.d.ts +2 -2
- package/omit.js +11 -2
- package/or.js +6 -0
- package/package.json +1 -3
- package/pick.js +9 -0
- package/pipe.js +30 -3
- package/reduce.js +132 -89
- package/set.js +9 -0
- package/some.js +17 -3
- package/switchCase.js +6 -0
- package/tap.js +14 -0
- package/thunkify.js +8 -0
- package/transform.js +112 -44
- package/tryCatch.js +5 -0
- package/x/append.js +3 -0
- package/x/callProp.js +5 -0
- package/x/defaultsDeep.d.ts +2 -2
- package/x/defaultsDeep.js +7 -2
- package/x/differenceWith.js +5 -0
- package/x/find.d.ts +2 -2
- package/x/find.js +2 -2
- package/x/groupBy.d.ts +2 -2
- package/x/groupBy.js +2 -2
- package/x/pluck.d.ts +2 -2
- package/x/pluck.js +2 -2
- package/x/unionWith.test.js +3 -3
package/reduce.js
CHANGED
|
@@ -3,17 +3,17 @@ const __ = require('./_internal/placeholder')
|
|
|
3
3
|
const curry3 = require('./_internal/curry3')
|
|
4
4
|
const genericReduce = require('./_internal/genericReduce')
|
|
5
5
|
|
|
6
|
-
// _reduce(collection any, reducer function,
|
|
7
|
-
const _reduce = function (collection, reducer,
|
|
8
|
-
if (typeof
|
|
9
|
-
const actualInitialValue =
|
|
6
|
+
// _reduce(collection any, reducer function, initial function|any) -> Promise
|
|
7
|
+
const _reduce = function (collection, reducer, initial) {
|
|
8
|
+
if (typeof initial == 'function') {
|
|
9
|
+
const actualInitialValue = initial(collection)
|
|
10
10
|
return isPromise(actualInitialValue)
|
|
11
11
|
? actualInitialValue.then(curry3(genericReduce, collection, reducer, __))
|
|
12
12
|
: genericReduce(collection, reducer, actualInitialValue)
|
|
13
13
|
}
|
|
14
|
-
return isPromise(
|
|
15
|
-
?
|
|
16
|
-
: genericReduce(collection, reducer,
|
|
14
|
+
return isPromise(initial)
|
|
15
|
+
? initial.then(curry3(genericReduce, collection, reducer, __))
|
|
16
|
+
: genericReduce(collection, reducer, initial)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -21,155 +21,181 @@ const _reduce = function (collection, reducer, initialValue) {
|
|
|
21
21
|
*
|
|
22
22
|
* @synopsis
|
|
23
23
|
* ```coffeescript [specscript]
|
|
24
|
-
* type Foldable = Array|
|
|
24
|
+
* type Foldable = Array|Set|Map|Generator|AsyncGenerator|{ reduce: function }|Object
|
|
25
25
|
*
|
|
26
26
|
* type Reducer = (
|
|
27
27
|
* accumulator any,
|
|
28
|
-
*
|
|
29
|
-
* indexOrKey
|
|
30
|
-
*
|
|
28
|
+
* item any,
|
|
29
|
+
* indexOrKey number|string|any,
|
|
30
|
+
* fold Foldable
|
|
31
31
|
* )=>(nextAccumulator Promise|any)
|
|
32
32
|
*
|
|
33
|
-
* type Resolver = (
|
|
33
|
+
* type Resolver = (fold Foldable)=>Promise|any
|
|
34
34
|
*
|
|
35
35
|
* reduce(
|
|
36
|
-
*
|
|
36
|
+
* fold Foldable,
|
|
37
37
|
* reducer Reducer,
|
|
38
|
-
*
|
|
38
|
+
* initial? Resolver|any
|
|
39
39
|
* ) -> result Promise|any
|
|
40
40
|
*
|
|
41
41
|
* reduce(
|
|
42
42
|
* reducer Reducer,
|
|
43
|
-
*
|
|
44
|
-
* )(
|
|
43
|
+
* initial? Resolver|any
|
|
44
|
+
* )(fold Foldable) -> result Promise|any
|
|
45
45
|
* ```
|
|
46
46
|
*
|
|
47
47
|
* @description
|
|
48
|
-
*
|
|
48
|
+
* Reduces a foldable to a single value.
|
|
49
|
+
*
|
|
50
|
+
* The following data types are considered to be foldables:
|
|
51
|
+
* * `array`
|
|
52
|
+
* * `set`
|
|
53
|
+
* * `map`
|
|
54
|
+
* * `generator`
|
|
55
|
+
* * `async generator`
|
|
56
|
+
* * `object with .reduce method`
|
|
57
|
+
* * `object`
|
|
58
|
+
*
|
|
59
|
+
* The reducing operation is dictated by a provided reducer function, which defines a transformation between the accumulator and a given item of the foldable.
|
|
60
|
+
*
|
|
61
|
+
* ```javascript
|
|
62
|
+
* const reducer = function (accumulator, item) {
|
|
63
|
+
* // nextAccumulator is the result of some operation between accumulator and item
|
|
64
|
+
* // and becomes the accumulator for the next iteration and invocation of the reducer
|
|
65
|
+
* return nextAccumulator
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
49
68
|
*
|
|
50
|
-
*
|
|
51
|
-
* * `Object`
|
|
52
|
-
* * `Set`
|
|
53
|
-
* * `Map`
|
|
54
|
-
* * `Iterator`/`Generator`
|
|
55
|
-
* * `AsyncIterator`/`AsyncGenerator`
|
|
69
|
+
* The reducer function signature changes depending on the provided foldable.
|
|
56
70
|
*
|
|
57
|
-
*
|
|
71
|
+
* If the foldable is an array:
|
|
72
|
+
* ```coffeescript [specscript]
|
|
73
|
+
* reducer(
|
|
74
|
+
* accumulator any,
|
|
75
|
+
* item any,
|
|
76
|
+
* index number,
|
|
77
|
+
* fold Array
|
|
78
|
+
* ) -> nextAccumulator Promise|any
|
|
79
|
+
* ```
|
|
58
80
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
81
|
+
* If the foldable is a set:
|
|
82
|
+
* ```coffeescript [specscript]
|
|
83
|
+
* reducer(
|
|
84
|
+
* accumulator any,
|
|
85
|
+
* item any
|
|
86
|
+
* ) -> nextAccumulator Promise|any
|
|
87
|
+
* ```
|
|
61
88
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
89
|
+
* If the foldable is a map:
|
|
90
|
+
* ```coffeescript [specscript]
|
|
91
|
+
* reducer(
|
|
92
|
+
* accumulator any,
|
|
93
|
+
* item any,
|
|
94
|
+
* key any,
|
|
95
|
+
* fold Map
|
|
96
|
+
* ) -> nextAccumulator Promise|any
|
|
97
|
+
* ```
|
|
65
98
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
99
|
+
* If the foldable is a generator:
|
|
100
|
+
* ```coffeescript [specscript]
|
|
101
|
+
* reducer(
|
|
102
|
+
* accumulator any,
|
|
103
|
+
* item any
|
|
104
|
+
* ) -> nextAccumulator Promise|any
|
|
69
105
|
* ```
|
|
70
106
|
*
|
|
71
|
-
* If
|
|
107
|
+
* If the foldable is a async generator:
|
|
108
|
+
* ```coffeescript [specscript]
|
|
109
|
+
* reducer(
|
|
110
|
+
* accumulator any,
|
|
111
|
+
* item any
|
|
112
|
+
* ) -> nextAccumulator Promise|any
|
|
113
|
+
* ```
|
|
72
114
|
*
|
|
73
|
-
*
|
|
74
|
-
* const add = (a, b) => a + b
|
|
115
|
+
* If the foldable is an object with a `.reduce` method, the reducer function signature is defined externally.
|
|
75
116
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
117
|
+
* If the foldable is a plain object:
|
|
118
|
+
* ```coffeescript [specscript]
|
|
119
|
+
* reducer(
|
|
120
|
+
* accumulator any,
|
|
121
|
+
* item any,
|
|
122
|
+
* key string,
|
|
123
|
+
* fold Object
|
|
124
|
+
* ) -> nextAccumulator Promise|any
|
|
78
125
|
* ```
|
|
79
126
|
*
|
|
80
|
-
*
|
|
127
|
+
* `reduce` executes a reducer function for each item of the array in order. If no initial value is provided, `reduce` uses the first item of the foldable as the initial value and starts iterating from the second item of the foldable.
|
|
81
128
|
*
|
|
82
129
|
* ```javascript [playground]
|
|
83
|
-
* const
|
|
84
|
-
*
|
|
85
|
-
* const contrivedInitializer = array => [`initial length ${array.length}`]
|
|
86
|
-
*
|
|
87
|
-
* const array = [1, 2, 3, 4, 5]
|
|
130
|
+
* const max = (a, b) => a > b ? a : b
|
|
88
131
|
*
|
|
89
|
-
*
|
|
90
|
-
* //
|
|
91
|
-
* console.log(reduce(array, concatSquares, contrivedInitializer))
|
|
92
|
-
* // ['initial length 5', 1, 4, 9, 16, 25]
|
|
132
|
+
* const result = reduce([1, 3, 5, 4, 2], max)
|
|
133
|
+
* console.log(result) // 5
|
|
93
134
|
* ```
|
|
94
135
|
*
|
|
95
|
-
*
|
|
136
|
+
* If an initial value is provided, the accumulator starts as the initial value rather than the first item of the foldable.
|
|
96
137
|
*
|
|
97
138
|
* ```javascript [playground]
|
|
98
139
|
* const add = (a, b) => a + b
|
|
99
140
|
*
|
|
100
|
-
* const
|
|
141
|
+
* const result = reduce([1, 2, 3, 4, 5], add, 0)
|
|
142
|
+
* console.log(result) // 15
|
|
143
|
+
* ```
|
|
101
144
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
145
|
+
* If the reducer is asynchronous, all promises created by the reducer are resolved before continuing with the reducing operation.
|
|
146
|
+
*
|
|
147
|
+
* ```javascript [playground]
|
|
148
|
+
* const asyncAdd = async (a, b) => a + b
|
|
105
149
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* ) // 15
|
|
150
|
+
* const promise = reduce([1, 2, 3, 4, 5], asyncAdd, 0)
|
|
151
|
+
* promise.then(console.log) // 15
|
|
109
152
|
* ```
|
|
110
153
|
*
|
|
111
|
-
*
|
|
154
|
+
* If the initialization parameter is a function, it is treated as a resolver of the initial value and called with the foldable.
|
|
112
155
|
*
|
|
113
156
|
* ```javascript [playground]
|
|
114
|
-
* const
|
|
157
|
+
* const concatSquares = (array, value) => array.concat(value ** 2)
|
|
115
158
|
*
|
|
116
|
-
* const
|
|
159
|
+
* const contrivedInitializer = array => [`initial length ${array.length}`]
|
|
117
160
|
*
|
|
118
|
-
*
|
|
119
|
-
* reduce(set, add)
|
|
120
|
-
* ) // 15
|
|
161
|
+
* const array = [1, 2, 3, 4, 5]
|
|
121
162
|
*
|
|
122
|
-
* console.log(
|
|
123
|
-
*
|
|
124
|
-
* ) // 15
|
|
163
|
+
* console.log(reduce(array, concatSquares, contrivedInitializer))
|
|
164
|
+
* // ['initial length 5', 1, 4, 9, 16, 25]
|
|
125
165
|
* ```
|
|
126
166
|
*
|
|
127
|
-
* For
|
|
167
|
+
* For objects, `reduce` iterates over just the values.
|
|
128
168
|
*
|
|
129
169
|
* ```javascript [playground]
|
|
130
170
|
* const add = (a, b) => a + b
|
|
131
171
|
*
|
|
132
|
-
* const
|
|
133
|
-
*
|
|
134
|
-
* console.log(
|
|
135
|
-
* reduce(m, add)
|
|
136
|
-
* ) // 15
|
|
172
|
+
* const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
|
137
173
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* ) // 15
|
|
174
|
+
* const result = reduce(obj, add)
|
|
175
|
+
* console.log(result) // 15
|
|
141
176
|
* ```
|
|
142
177
|
*
|
|
143
|
-
* For
|
|
178
|
+
* For maps, `reduce` iterates over the values of the entries.
|
|
144
179
|
*
|
|
145
180
|
* ```javascript [playground]
|
|
146
181
|
* const add = (a, b) => a + b
|
|
147
182
|
*
|
|
148
|
-
* const
|
|
149
|
-
* yield 1; yield 2; yield 3; yield 4; yield 5
|
|
150
|
-
* }
|
|
151
|
-
*
|
|
152
|
-
* console.log(
|
|
153
|
-
* reduce(generate12345(), add)
|
|
154
|
-
* ) // 15
|
|
183
|
+
* const m = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
|
|
155
184
|
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* ) // 15
|
|
185
|
+
* const result = reduce(m, add)
|
|
186
|
+
* console.log(result) // 15
|
|
159
187
|
* ```
|
|
160
188
|
*
|
|
161
|
-
*
|
|
189
|
+
* `reduce` works for async generators.
|
|
162
190
|
*
|
|
163
191
|
* ```javascript [playground]
|
|
164
192
|
* const asyncAdd = async (a, b) => a + b
|
|
165
193
|
*
|
|
166
|
-
* const
|
|
194
|
+
* const asyncGenerate = async function* () {
|
|
167
195
|
* yield 1; yield 2; yield 3; yield 4; yield 5
|
|
168
196
|
* }
|
|
169
197
|
*
|
|
170
|
-
* reduce(
|
|
171
|
-
*
|
|
172
|
-
* reduce(asyncAdd)(asyncGenerate12345()).then(console.log) // 15
|
|
198
|
+
* reduce(asyncGenerate(), asyncAdd).then(console.log) // 15
|
|
173
199
|
* ```
|
|
174
200
|
*
|
|
175
201
|
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
@@ -180,6 +206,23 @@ const _reduce = function (collection, reducer, initialValue) {
|
|
|
180
206
|
* reduce(Promise.resolve([1, 2, 3, 4, 5]), add, 0).then(console.log) // 15
|
|
181
207
|
* ```
|
|
182
208
|
*
|
|
209
|
+
* Any promises passed for the initial value are also resolved before further execution.
|
|
210
|
+
*
|
|
211
|
+
* ```javascript [playground]
|
|
212
|
+
* const add = (a, b) => a + b
|
|
213
|
+
*
|
|
214
|
+
* const promise = reduce([1, 2, 3, 4, 5], add, Promise.resolve(0))
|
|
215
|
+
* promise.then(console.log) // 15
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* See also:
|
|
219
|
+
* * [forEach](/docs/forEach)
|
|
220
|
+
* * [map](/docs/map)
|
|
221
|
+
* * [filter](/docs/filter)
|
|
222
|
+
* * [transform](/docs/transform)
|
|
223
|
+
* * [flatMap](/docs/flatMap)
|
|
224
|
+
* * [some](/docs/some)
|
|
225
|
+
*
|
|
183
226
|
* @execution series
|
|
184
227
|
*
|
|
185
228
|
* @transducing
|
package/set.js
CHANGED
|
@@ -96,6 +96,15 @@ const _set = function (obj, path, value) {
|
|
|
96
96
|
* set(Promise.resolve({}), 'a', 1).then(console.log) // { a: 1 }
|
|
97
97
|
* ```
|
|
98
98
|
*
|
|
99
|
+
* See also:
|
|
100
|
+
* * [pipe](/docs/pipe)
|
|
101
|
+
* * [all](/docs/all)
|
|
102
|
+
* * [assign](/docs/assign)
|
|
103
|
+
* * [get](/docs/get)
|
|
104
|
+
* * [pick](/docs/pick)
|
|
105
|
+
* * [omit](/docs/omit)
|
|
106
|
+
* * [forEach](/docs/forEach)
|
|
107
|
+
*
|
|
99
108
|
* @since 1.7.0
|
|
100
109
|
*/
|
|
101
110
|
|
package/some.js
CHANGED
|
@@ -40,7 +40,7 @@ const _some = function (collection, predicate) {
|
|
|
40
40
|
*
|
|
41
41
|
* @synopsis
|
|
42
42
|
* ```coffeescript [specscript]
|
|
43
|
-
* type Foldable = Array|
|
|
43
|
+
* type Foldable = Array|Set|Map|Generator|AsyncGenerator|{ reduce: function }|Object
|
|
44
44
|
*
|
|
45
45
|
* some(collection Foldable, predicate function) -> Promise|boolean
|
|
46
46
|
*
|
|
@@ -48,7 +48,7 @@ const _some = function (collection, predicate) {
|
|
|
48
48
|
* ```
|
|
49
49
|
*
|
|
50
50
|
* @description
|
|
51
|
-
* Test a predicate concurrently across all items of a
|
|
51
|
+
* Test a predicate concurrently across all items of a foldable, returning true if any executions return true.
|
|
52
52
|
*
|
|
53
53
|
* ```javascript [playground]
|
|
54
54
|
* const isOdd = number => number % 2 == 1
|
|
@@ -58,7 +58,16 @@ const _some = function (collection, predicate) {
|
|
|
58
58
|
* ) // true
|
|
59
59
|
* ```
|
|
60
60
|
*
|
|
61
|
-
* The
|
|
61
|
+
* The following data types are considered to be foldables:
|
|
62
|
+
* * `array`
|
|
63
|
+
* * `set`
|
|
64
|
+
* * `map`
|
|
65
|
+
* * `generator`
|
|
66
|
+
* * `async generator`
|
|
67
|
+
* * `object with .reduce method`
|
|
68
|
+
* * `object`
|
|
69
|
+
*
|
|
70
|
+
* `some` works for async generators.
|
|
62
71
|
*
|
|
63
72
|
* ```javascript [playground]
|
|
64
73
|
* const toTodosUrl = id => 'https://jsonplaceholder.typicode.com/todos/' + id
|
|
@@ -98,6 +107,11 @@ const _some = function (collection, predicate) {
|
|
|
98
107
|
* some(Promise.resolve([1, 2, 3, 4, 5]), n => n > 6).then(console.log) // false
|
|
99
108
|
* ```
|
|
100
109
|
*
|
|
110
|
+
* See also:
|
|
111
|
+
* * [map](/docs/map)
|
|
112
|
+
* * [every](/docs/every)
|
|
113
|
+
* * [and](/docs/and)
|
|
114
|
+
*
|
|
101
115
|
* @execution concurrent
|
|
102
116
|
*
|
|
103
117
|
* @muxing
|
package/switchCase.js
CHANGED
|
@@ -91,6 +91,12 @@ const curryArgs3 = require('./_internal/curryArgs3')
|
|
|
91
91
|
* ]) // 1 + 2 + 3 == 6
|
|
92
92
|
* ```
|
|
93
93
|
*
|
|
94
|
+
* See also:
|
|
95
|
+
* * [pipe](/docs/pipe)
|
|
96
|
+
* * [tap.if](/docs/tap.if)
|
|
97
|
+
* * [tryCatch](/docs/tryCatch)
|
|
98
|
+
* * [all](/docs/all)
|
|
99
|
+
*
|
|
94
100
|
* @execution series
|
|
95
101
|
*/
|
|
96
102
|
const switchCase = (...args) => {
|
package/tap.js
CHANGED
|
@@ -46,6 +46,13 @@ const _tap = function (args, f) {
|
|
|
46
46
|
* ```javascript [playground]
|
|
47
47
|
* tap(Promise.resolve(1), Promise.resolve(2), 3, console.log) // 1 2 3
|
|
48
48
|
* ```
|
|
49
|
+
*
|
|
50
|
+
* See also:
|
|
51
|
+
* * [pipe](/docs/pipe)
|
|
52
|
+
* * [compose](/docs/compose)
|
|
53
|
+
* * [tap.if](/docs/tap.if)
|
|
54
|
+
* * [switchCase](/docs/switchCase)
|
|
55
|
+
* * [tryCatch](/docs/tryCatch)
|
|
49
56
|
*/
|
|
50
57
|
const tap = function (...args) {
|
|
51
58
|
const f = args.pop()
|
|
@@ -116,6 +123,13 @@ const _tapIf = function (predicate, f, args) {
|
|
|
116
123
|
* tap.if(Promise.resolve(1), n => n < 5, console.log) // 1
|
|
117
124
|
* tap.if(Promise.resolve(6), n => n < 5, console.log)
|
|
118
125
|
* ```
|
|
126
|
+
*
|
|
127
|
+
* See also:
|
|
128
|
+
* * [pipe](/docs/pipe)
|
|
129
|
+
* * [compose](/docs/compose)
|
|
130
|
+
* * [tap](/docs/tap)
|
|
131
|
+
* * [switchCase](/docs/switchCase)
|
|
132
|
+
* * [tryCatch](/docs/tryCatch)
|
|
119
133
|
*/
|
|
120
134
|
|
|
121
135
|
tap.if = function (...args) {
|
package/thunkify.js
CHANGED
|
@@ -22,6 +22,14 @@ const funcApply = require('./_internal/funcApply')
|
|
|
22
22
|
*
|
|
23
23
|
* console.log(thunkAdd12()) // 3
|
|
24
24
|
* ```
|
|
25
|
+
*
|
|
26
|
+
* See also:
|
|
27
|
+
* * [eq](/docs/eq)
|
|
28
|
+
* * [always](/docs/always)
|
|
29
|
+
* * [curry](/docs/curry)
|
|
30
|
+
* * [__](/docs/__)
|
|
31
|
+
* * [Transducer.map](/docs/Transducer.map)
|
|
32
|
+
*
|
|
25
33
|
*/
|
|
26
34
|
const thunkify = (func, ...args) => function thunk() {
|
|
27
35
|
if (areAnyValuesPromises(args)) {
|
package/transform.js
CHANGED
|
@@ -21,46 +21,106 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
21
21
|
*
|
|
22
22
|
* @synopsis
|
|
23
23
|
* ```coffeescript [specscript]
|
|
24
|
-
* type Foldable =
|
|
24
|
+
* type Foldable = Array|Set|Map|Generator|AsyncGenerator|{ reduce: function }|Object
|
|
25
25
|
*
|
|
26
26
|
* type Reducer = (
|
|
27
27
|
* accumulator any,
|
|
28
28
|
* value any,
|
|
29
|
-
* indexOrKey? number|string,
|
|
30
|
-
* collection? Foldable,
|
|
31
29
|
* )=>(nextAccumulator Promise|any)
|
|
32
30
|
*
|
|
33
31
|
* type Transducer = Reducer=>Reducer
|
|
34
32
|
*
|
|
35
|
-
* type
|
|
33
|
+
* type Semigroup =
|
|
36
34
|
* Array|String|Set|TypedArray|{ concat: function }|{ write: function }|Object
|
|
37
35
|
*
|
|
38
|
-
* type
|
|
36
|
+
* type SemigroupResolver = (fold Foldable)=>Promise|Semigroup
|
|
39
37
|
*
|
|
40
38
|
* transform(
|
|
41
|
-
*
|
|
39
|
+
* fold Foldable,
|
|
42
40
|
* transducer Transducer,
|
|
43
|
-
*
|
|
44
|
-
* ) -> result Promise|
|
|
41
|
+
* initial? Semigroup|SemigroupResolver,
|
|
42
|
+
* ) -> result Promise|Semigroup
|
|
45
43
|
*
|
|
46
44
|
* transform(
|
|
47
45
|
* transducer Transducer,
|
|
48
|
-
*
|
|
49
|
-
* )(
|
|
46
|
+
* initial? Semigroup|SemigroupResolver,
|
|
47
|
+
* )(fold Foldable) -> result Promise|Semigroup
|
|
50
48
|
* ```
|
|
51
49
|
*
|
|
52
50
|
* @description
|
|
53
|
-
* Transforms a
|
|
51
|
+
* Transforms a foldable with [transducers](https://rubico.land/blog/transducers-crash-course-rubico-v2) into a semigroup.
|
|
54
52
|
*
|
|
55
|
-
*
|
|
56
|
-
* * `
|
|
57
|
-
* * `
|
|
58
|
-
* * `
|
|
59
|
-
* * `
|
|
60
|
-
* * `
|
|
61
|
-
* * `
|
|
53
|
+
* The following data types are considered to be foldables:
|
|
54
|
+
* * `array`
|
|
55
|
+
* * `set`
|
|
56
|
+
* * `map`
|
|
57
|
+
* * `generator`
|
|
58
|
+
* * `async generator`
|
|
59
|
+
* * `object with .reduce method`
|
|
60
|
+
* * `object`
|
|
62
61
|
*
|
|
63
|
-
*
|
|
62
|
+
* Transducers, due to their lazy nature, don't have knowledge of the foldable they are transforming. As such, the transducer signature for all foldables is the same:
|
|
63
|
+
*
|
|
64
|
+
* ```coffeescript [specscript]
|
|
65
|
+
* type Reducer = (
|
|
66
|
+
* accumulator any,
|
|
67
|
+
* value any,
|
|
68
|
+
* )=>(nextAccumulator Promise|any)
|
|
69
|
+
*
|
|
70
|
+
* type Transducer = Reducer=>Reducer
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* The following data types are considered to be semigroups:
|
|
74
|
+
* * `array`
|
|
75
|
+
* * `string`
|
|
76
|
+
* * `set`
|
|
77
|
+
* * `binary`
|
|
78
|
+
* * `{ concat: function }`
|
|
79
|
+
* * `{ write: function }`
|
|
80
|
+
* * `object`
|
|
81
|
+
*
|
|
82
|
+
* The concatenation operation changes depending on the provided semigroup:
|
|
83
|
+
*
|
|
84
|
+
* If the semigroup is an array, concatenation is defined as:
|
|
85
|
+
* ```javascript
|
|
86
|
+
* nextAccumulator = accumulator.concat(values)
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* If the semigroup is a string, concatenation is defined as:
|
|
90
|
+
* ```javascript
|
|
91
|
+
* nextAccumulator = accumulator + values
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* If the semigroup is a set, concatenation is defined as:
|
|
95
|
+
* ```javascript
|
|
96
|
+
* nextAccumulator = accumulator.add(...values)
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* If the semigroup is binary, concatenation is defined as:
|
|
100
|
+
* ```javascript
|
|
101
|
+
* nextAccumulator = new accumulator.constructor(accumulator.length + values.length)
|
|
102
|
+
* nextAccumulator.set(accumulator)
|
|
103
|
+
* nextAccumulator.set(values, accumulator.length)
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* If the semigroup is an object with a `.concat` method, concatenation is defined as:
|
|
107
|
+
* ```javascript
|
|
108
|
+
* nextAccumulator = accumulator
|
|
109
|
+
* accumulator.concat(values)
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* If the semigroup is an object with a `.write` method, concatenation is defined as:
|
|
113
|
+
* ```javascript
|
|
114
|
+
* nextAccumulator = accumulator
|
|
115
|
+
* accumulator.write(values)
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* If the semigroup is a plain object, concatenation is defined as:
|
|
119
|
+
* ```javascript
|
|
120
|
+
* nextAccumulator = ({ ...accumulator, ...values })
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* `transform` transforms numbers from an array into another array.
|
|
64
124
|
*
|
|
65
125
|
* ```javascript [playground]
|
|
66
126
|
* const square = number => number ** 2
|
|
@@ -74,26 +134,26 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
74
134
|
*
|
|
75
135
|
* // transform arrays into arrays
|
|
76
136
|
* console.log(
|
|
77
|
-
* transform(
|
|
137
|
+
* transform([1, 2, 3, 4, 5], squaredOdds, [])
|
|
78
138
|
* ) // [1, 9, 25]
|
|
79
139
|
*
|
|
80
140
|
* // transform arrays into strings
|
|
81
141
|
* console.log(
|
|
82
|
-
* transform(
|
|
142
|
+
* transform([1, 2, 3, 4, 5], squaredOdds, '')
|
|
83
143
|
* ) // '1925'
|
|
84
144
|
*
|
|
85
145
|
* // transform arrays into sets
|
|
86
146
|
* console.log(
|
|
87
|
-
* transform(
|
|
147
|
+
* transform([1, 2, 3, 4, 5], squaredOdds, new Set())
|
|
88
148
|
* ) // Set (3) { 1, 9, 25 }
|
|
89
149
|
*
|
|
90
150
|
* // transform arrays into typed arrays
|
|
91
151
|
* console.log(
|
|
92
|
-
* transform(
|
|
152
|
+
* transform([1, 2, 3, 4, 5], squaredOdds, new Uint8Array()),
|
|
93
153
|
* ) // Uint8Array(3) [ 1, 9, 25 ]
|
|
94
154
|
* ```
|
|
95
155
|
*
|
|
96
|
-
* `transform` arrays into objects that implement `.concat`.
|
|
156
|
+
* `transform` transforms arrays into objects that implement `.concat`.
|
|
97
157
|
*
|
|
98
158
|
* ```javascript [playground]
|
|
99
159
|
* const square = number => number ** 2
|
|
@@ -105,7 +165,7 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
105
165
|
* },
|
|
106
166
|
* }
|
|
107
167
|
*
|
|
108
|
-
* transform(
|
|
168
|
+
* transform([1, 2, 3, 4, 5], Transducer.map(square), Stdout)
|
|
109
169
|
* // 1
|
|
110
170
|
* // 4
|
|
111
171
|
* // 9
|
|
@@ -113,9 +173,9 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
113
173
|
* // 25
|
|
114
174
|
* ```
|
|
115
175
|
*
|
|
116
|
-
* `transform` an async generator into `process.stdout`, a Node.js writable stream that implements `.write`.
|
|
176
|
+
* `transform` transforms an async generator into `process.stdout`, a Node.js writable stream that implements `.write`.
|
|
117
177
|
*
|
|
118
|
-
* ```javascript
|
|
178
|
+
* ```javascript
|
|
119
179
|
* const { pipe, compose, transform } = rubico
|
|
120
180
|
* // global Transducer
|
|
121
181
|
*
|
|
@@ -133,40 +193,48 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
133
193
|
* }
|
|
134
194
|
* }
|
|
135
195
|
*
|
|
136
|
-
* const Stdout = {
|
|
137
|
-
* concat(...args) {
|
|
138
|
-
* console.log(...args)
|
|
139
|
-
* return this
|
|
140
|
-
* },
|
|
141
|
-
* }
|
|
142
|
-
*
|
|
143
196
|
* transform(
|
|
144
197
|
* streamRandomInts(10),
|
|
145
198
|
* compose([
|
|
146
199
|
* Transducer.map(square),
|
|
147
200
|
* Transducer.map(toString),
|
|
148
201
|
* ]),
|
|
149
|
-
*
|
|
202
|
+
* process.stdout // 2893600784289441449001600409684644624324923044411225
|
|
150
203
|
* )
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* If the initial value is a function it is treated as a resolver of the semigroup. The resolver may be asynchronous.
|
|
207
|
+
*
|
|
208
|
+
* ```javascript [playground]
|
|
209
|
+
* const promise = transform(
|
|
210
|
+
* [1, 2, 3, 4, 5],
|
|
211
|
+
* Transducer.map(number => number ** 2),
|
|
212
|
+
* async () => ['a'],
|
|
213
|
+
* )
|
|
214
|
+
*
|
|
215
|
+
* promise.then(console.log)
|
|
158
216
|
* ```
|
|
159
217
|
*
|
|
160
218
|
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
161
219
|
*
|
|
162
220
|
* ```javascript [playground]
|
|
163
|
-
* transform(
|
|
221
|
+
* const promise = transform(
|
|
164
222
|
* Promise.resolve([1, 2, 3, 4, 5]),
|
|
165
223
|
* Transducer.map(n => n ** 2),
|
|
166
224
|
* [],
|
|
167
|
-
* )
|
|
225
|
+
* )
|
|
226
|
+
*
|
|
227
|
+
* promise.then(console.log) // [1, 4, 9, 16, 25]
|
|
168
228
|
* ```
|
|
169
229
|
*
|
|
230
|
+
* See also:
|
|
231
|
+
* * [forEach](/docs/forEach)
|
|
232
|
+
* * [map](/docs/map)
|
|
233
|
+
* * [filter](/docs/filter)
|
|
234
|
+
* * [reduce](/docs/reduce)
|
|
235
|
+
* * [flatMap](/docs/flatMap)
|
|
236
|
+
* * [some](/docs/some)
|
|
237
|
+
*
|
|
170
238
|
* @execution series
|
|
171
239
|
*
|
|
172
240
|
* @transducing
|