rubico 2.5.0 → 2.6.1
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/_internal/arrayMapPool.js +11 -19
- package/_internal/mapMapPool.js +80 -0
- package/_internal/objectMapPool.js +77 -0
- package/_internal/objectMapSeries.js +1 -0
- package/_internal/setMapPool.js +79 -0
- package/_internal/stringMapPool.js +22 -0
- package/all.js +11 -1
- package/and.js +9 -0
- package/assign.js +14 -1
- package/compose.js +8 -0
- package/dist/Transducer.es.js +1 -1
- package/dist/Transducer.es.min.js +1 -1
- package/dist/Transducer.js +1 -1
- package/dist/Transducer.min.js +1 -1
- package/dist/Transducer.mjs +1 -1
- package/dist/__.es.js +1 -1
- package/dist/__.es.min.js +1 -1
- package/dist/__.js +1 -1
- package/dist/__.min.js +1 -1
- package/dist/__.mjs +1 -1
- package/dist/all.es.js +1 -1
- package/dist/all.es.min.js +1 -1
- package/dist/all.js +1 -1
- package/dist/all.min.js +1 -1
- package/dist/all.mjs +1 -1
- package/dist/always.es.js +1 -1
- package/dist/always.es.min.js +1 -1
- package/dist/always.js +1 -1
- package/dist/always.min.js +1 -1
- package/dist/always.mjs +1 -1
- package/dist/and.es.js +1 -1
- package/dist/and.es.min.js +1 -1
- package/dist/and.js +1 -1
- package/dist/and.min.js +1 -1
- package/dist/and.mjs +1 -1
- package/dist/assign.es.js +1 -1
- package/dist/assign.es.min.js +1 -1
- package/dist/assign.js +1 -1
- package/dist/assign.min.js +1 -1
- package/dist/assign.mjs +1 -1
- package/dist/compose.es.js +1 -1
- package/dist/compose.es.min.js +1 -1
- package/dist/compose.js +1 -1
- package/dist/compose.min.js +1 -1
- package/dist/compose.mjs +1 -1
- package/dist/curry.es.js +1 -1
- package/dist/curry.es.min.js +1 -1
- package/dist/curry.js +1 -1
- package/dist/curry.min.js +1 -1
- package/dist/curry.mjs +1 -1
- package/dist/eq.es.js +1 -1
- package/dist/eq.es.min.js +1 -1
- package/dist/eq.js +1 -1
- package/dist/eq.min.js +1 -1
- package/dist/eq.mjs +1 -1
- package/dist/every.es.js +1 -1
- package/dist/every.es.min.js +1 -1
- package/dist/every.js +1 -1
- package/dist/every.min.js +1 -1
- package/dist/every.mjs +1 -1
- package/dist/filter.es.js +1 -1
- package/dist/filter.es.min.js +1 -1
- package/dist/filter.js +1 -1
- package/dist/filter.min.js +1 -1
- package/dist/filter.mjs +1 -1
- package/dist/flatMap.es.js +1 -1
- package/dist/flatMap.es.min.js +1 -1
- package/dist/flatMap.js +1 -1
- package/dist/flatMap.min.js +1 -1
- package/dist/flatMap.mjs +1 -1
- package/dist/forEach.es.js +3 -2
- package/dist/forEach.es.min.js +2 -2
- package/dist/forEach.js +3 -2
- package/dist/forEach.min.js +2 -2
- package/dist/forEach.mjs +3 -2
- package/dist/get.es.js +1 -1
- package/dist/get.es.min.js +1 -1
- package/dist/get.js +1 -1
- package/dist/get.min.js +1 -1
- package/dist/get.mjs +1 -1
- package/dist/gt.es.js +1 -1
- package/dist/gt.es.min.js +1 -1
- package/dist/gt.js +1 -1
- package/dist/gt.min.js +1 -1
- package/dist/gt.mjs +1 -1
- package/dist/gte.es.js +1 -1
- package/dist/gte.es.min.js +1 -1
- package/dist/gte.js +1 -1
- package/dist/gte.min.js +1 -1
- package/dist/gte.mjs +1 -1
- package/dist/lt.es.js +1 -1
- package/dist/lt.es.min.js +1 -1
- package/dist/lt.js +1 -1
- package/dist/lt.min.js +1 -1
- package/dist/lt.mjs +1 -1
- package/dist/lte.es.js +1 -1
- package/dist/lte.es.min.js +1 -1
- package/dist/lte.js +1 -1
- package/dist/lte.min.js +1 -1
- package/dist/lte.mjs +1 -1
- package/dist/map.es.js +221 -44
- package/dist/map.es.min.js +2 -2
- package/dist/map.js +221 -44
- package/dist/map.min.js +2 -2
- package/dist/map.mjs +221 -44
- package/dist/not.es.js +1 -1
- package/dist/not.es.min.js +1 -1
- package/dist/not.js +1 -1
- package/dist/not.min.js +1 -1
- package/dist/not.mjs +1 -1
- package/dist/omit.es.js +1 -1
- package/dist/omit.es.min.js +1 -1
- package/dist/omit.js +1 -1
- package/dist/omit.min.js +1 -1
- package/dist/omit.mjs +1 -1
- package/dist/or.es.js +1 -1
- package/dist/or.es.min.js +1 -1
- package/dist/or.js +1 -1
- package/dist/or.min.js +1 -1
- package/dist/or.mjs +1 -1
- package/dist/pick.es.js +1 -1
- package/dist/pick.es.min.js +1 -1
- package/dist/pick.js +1 -1
- package/dist/pick.min.js +1 -1
- package/dist/pick.mjs +1 -1
- package/dist/pipe.es.js +1 -1
- package/dist/pipe.es.min.js +1 -1
- package/dist/pipe.js +1 -1
- package/dist/pipe.min.js +1 -1
- package/dist/pipe.mjs +1 -1
- package/dist/reduce.es.js +1 -1
- package/dist/reduce.es.min.js +1 -1
- package/dist/reduce.js +1 -1
- package/dist/reduce.min.js +1 -1
- package/dist/reduce.mjs +1 -1
- package/dist/rubico.es.js +259 -60
- package/dist/rubico.es.min.js +2 -2
- package/dist/rubico.global.js +259 -60
- package/dist/rubico.global.min.js +2 -2
- package/dist/rubico.js +259 -60
- package/dist/rubico.min.js +2 -2
- package/dist/rubico.mjs +259 -60
- package/dist/set.es.js +1 -1
- package/dist/set.es.min.js +1 -1
- package/dist/set.js +1 -1
- package/dist/set.min.js +1 -1
- package/dist/set.mjs +1 -1
- package/dist/some.es.js +1 -1
- package/dist/some.es.min.js +1 -1
- package/dist/some.js +1 -1
- package/dist/some.min.js +1 -1
- package/dist/some.mjs +1 -1
- package/dist/switchCase.es.js +1 -1
- package/dist/switchCase.es.min.js +1 -1
- package/dist/switchCase.js +1 -1
- package/dist/switchCase.min.js +1 -1
- package/dist/switchCase.mjs +1 -1
- package/dist/tap.es.js +100 -14
- package/dist/tap.es.min.js +2 -2
- package/dist/tap.js +100 -14
- package/dist/tap.min.js +2 -2
- package/dist/tap.mjs +100 -14
- package/dist/thunkify.es.js +1 -1
- package/dist/thunkify.es.min.js +1 -1
- package/dist/thunkify.js +1 -1
- package/dist/thunkify.min.js +1 -1
- package/dist/thunkify.mjs +1 -1
- package/dist/transform.es.js +1 -1
- package/dist/transform.es.min.js +1 -1
- package/dist/transform.js +1 -1
- package/dist/transform.min.js +1 -1
- package/dist/transform.mjs +1 -1
- package/dist/tryCatch.es.js +1 -1
- package/dist/tryCatch.es.min.js +1 -1
- package/dist/tryCatch.js +1 -1
- package/dist/tryCatch.min.js +1 -1
- package/dist/tryCatch.mjs +1 -1
- package/dist/x/append.es.js +1 -1
- package/dist/x/append.es.min.js +1 -1
- package/dist/x/append.js +1 -1
- package/dist/x/append.min.js +1 -1
- package/dist/x/append.mjs +1 -1
- package/dist/x/callProp.es.js +1 -1
- package/dist/x/callProp.es.min.js +1 -1
- package/dist/x/callProp.js +1 -1
- package/dist/x/callProp.min.js +1 -1
- package/dist/x/callProp.mjs +1 -1
- package/dist/x/defaultsDeep.es.js +1 -1
- package/dist/x/defaultsDeep.es.min.js +1 -1
- package/dist/x/defaultsDeep.js +1 -1
- package/dist/x/defaultsDeep.min.js +1 -1
- package/dist/x/defaultsDeep.mjs +1 -1
- package/dist/x/differenceWith.es.js +1 -1
- package/dist/x/differenceWith.es.min.js +1 -1
- package/dist/x/differenceWith.js +1 -1
- package/dist/x/differenceWith.min.js +1 -1
- package/dist/x/differenceWith.mjs +1 -1
- package/dist/x/filterOut.es.js +1 -1
- package/dist/x/filterOut.es.min.js +1 -1
- package/dist/x/filterOut.js +1 -1
- package/dist/x/filterOut.min.js +1 -1
- package/dist/x/filterOut.mjs +1 -1
- package/dist/x/find.es.js +1 -1
- package/dist/x/find.es.min.js +1 -1
- package/dist/x/find.js +1 -1
- package/dist/x/find.min.js +1 -1
- package/dist/x/find.mjs +1 -1
- package/dist/x/findIndex.es.js +1 -1
- package/dist/x/findIndex.es.min.js +1 -1
- package/dist/x/findIndex.js +1 -1
- package/dist/x/findIndex.min.js +1 -1
- package/dist/x/findIndex.mjs +1 -1
- package/dist/x/first.es.js +1 -1
- package/dist/x/first.es.min.js +1 -1
- package/dist/x/first.js +1 -1
- package/dist/x/first.min.js +1 -1
- package/dist/x/first.mjs +1 -1
- package/dist/x/flatten.es.js +1 -1
- package/dist/x/flatten.es.min.js +1 -1
- package/dist/x/flatten.js +1 -1
- package/dist/x/flatten.min.js +1 -1
- package/dist/x/flatten.mjs +1 -1
- package/dist/x/groupBy.es.js +1 -1
- package/dist/x/groupBy.es.min.js +1 -1
- package/dist/x/groupBy.js +1 -1
- package/dist/x/groupBy.min.js +1 -1
- package/dist/x/groupBy.mjs +1 -1
- package/dist/x/has.es.js +1 -1
- package/dist/x/has.es.min.js +1 -1
- package/dist/x/has.js +1 -1
- package/dist/x/has.min.js +1 -1
- package/dist/x/has.mjs +1 -1
- package/dist/x/identity.es.js +1 -1
- package/dist/x/identity.es.min.js +1 -1
- package/dist/x/identity.js +1 -1
- package/dist/x/identity.min.js +1 -1
- package/dist/x/identity.mjs +1 -1
- package/dist/x/includes.es.js +1 -1
- package/dist/x/includes.es.min.js +1 -1
- package/dist/x/includes.js +1 -1
- package/dist/x/includes.min.js +1 -1
- package/dist/x/includes.mjs +1 -1
- package/dist/x/isDeepEqual.es.js +1 -1
- package/dist/x/isDeepEqual.es.min.js +1 -1
- package/dist/x/isDeepEqual.js +1 -1
- package/dist/x/isDeepEqual.min.js +1 -1
- package/dist/x/isDeepEqual.mjs +1 -1
- package/dist/x/isEmpty.es.js +1 -1
- package/dist/x/isEmpty.es.min.js +1 -1
- package/dist/x/isEmpty.js +1 -1
- package/dist/x/isEmpty.min.js +1 -1
- package/dist/x/isEmpty.mjs +1 -1
- package/dist/x/isEqual.es.js +1 -1
- package/dist/x/isEqual.es.min.js +1 -1
- package/dist/x/isEqual.js +1 -1
- package/dist/x/isEqual.min.js +1 -1
- package/dist/x/isEqual.mjs +1 -1
- package/dist/x/isFunction.es.js +1 -1
- package/dist/x/isFunction.es.min.js +1 -1
- package/dist/x/isFunction.js +1 -1
- package/dist/x/isFunction.min.js +1 -1
- package/dist/x/isFunction.mjs +1 -1
- package/dist/x/isIn.es.js +1 -1
- package/dist/x/isIn.es.min.js +1 -1
- package/dist/x/isIn.js +1 -1
- package/dist/x/isIn.min.js +1 -1
- package/dist/x/isIn.mjs +1 -1
- package/dist/x/isObject.es.js +1 -1
- package/dist/x/isObject.es.min.js +1 -1
- package/dist/x/isObject.js +1 -1
- package/dist/x/isObject.min.js +1 -1
- package/dist/x/isObject.mjs +1 -1
- package/dist/x/isString.es.js +1 -1
- package/dist/x/isString.es.min.js +1 -1
- package/dist/x/isString.js +1 -1
- package/dist/x/isString.min.js +1 -1
- package/dist/x/isString.mjs +1 -1
- package/dist/x/keys.es.js +1 -1
- package/dist/x/keys.es.min.js +1 -1
- package/dist/x/keys.js +1 -1
- package/dist/x/keys.min.js +1 -1
- package/dist/x/keys.mjs +1 -1
- package/dist/x/last.es.js +1 -1
- package/dist/x/last.es.min.js +1 -1
- package/dist/x/last.js +1 -1
- package/dist/x/last.min.js +1 -1
- package/dist/x/last.mjs +1 -1
- package/dist/x/maxBy.es.js +1 -1
- package/dist/x/maxBy.es.min.js +1 -1
- package/dist/x/maxBy.js +1 -1
- package/dist/x/maxBy.min.js +1 -1
- package/dist/x/maxBy.mjs +1 -1
- package/dist/x/noop.es.js +1 -1
- package/dist/x/noop.es.min.js +1 -1
- package/dist/x/noop.js +1 -1
- package/dist/x/noop.min.js +1 -1
- package/dist/x/noop.mjs +1 -1
- package/dist/x/pluck.es.js +221 -44
- package/dist/x/pluck.es.min.js +2 -2
- package/dist/x/pluck.js +221 -44
- package/dist/x/pluck.min.js +2 -2
- package/dist/x/pluck.mjs +221 -44
- package/dist/x/prepend.es.js +1 -1
- package/dist/x/prepend.es.min.js +1 -1
- package/dist/x/prepend.js +1 -1
- package/dist/x/prepend.min.js +1 -1
- package/dist/x/prepend.mjs +1 -1
- package/dist/x/size.es.js +1 -1
- package/dist/x/size.es.min.js +1 -1
- package/dist/x/size.js +1 -1
- package/dist/x/size.min.js +1 -1
- package/dist/x/size.mjs +1 -1
- package/dist/x/trace.es.js +100 -14
- package/dist/x/trace.es.min.js +2 -2
- package/dist/x/trace.js +100 -14
- package/dist/x/trace.min.js +2 -2
- package/dist/x/trace.mjs +100 -14
- package/dist/x/unionWith.es.js +1 -1
- package/dist/x/unionWith.es.min.js +1 -1
- package/dist/x/unionWith.js +1 -1
- package/dist/x/unionWith.min.js +1 -1
- package/dist/x/unionWith.mjs +1 -1
- package/dist/x/uniq.es.js +1 -1
- package/dist/x/uniq.es.min.js +1 -1
- package/dist/x/uniq.js +1 -1
- package/dist/x/uniq.min.js +1 -1
- package/dist/x/uniq.mjs +1 -1
- package/dist/x/unless.es.js +1 -1
- package/dist/x/unless.es.min.js +1 -1
- package/dist/x/unless.js +1 -1
- package/dist/x/unless.min.js +1 -1
- package/dist/x/unless.mjs +1 -1
- package/dist/x/values.es.js +1 -1
- package/dist/x/values.es.min.js +1 -1
- package/dist/x/values.js +1 -1
- package/dist/x/values.min.js +1 -1
- package/dist/x/values.mjs +1 -1
- package/dist/x/when.es.js +1 -1
- package/dist/x/when.es.min.js +1 -1
- package/dist/x/when.js +1 -1
- package/dist/x/when.min.js +1 -1
- package/dist/x/when.mjs +1 -1
- package/eq.js +6 -0
- package/es.js +259 -60
- package/every.js +6 -0
- package/filter.js +9 -0
- package/flatMap.js +7 -0
- package/forEach.js +20 -1
- package/get.js +6 -0
- package/gt.js +6 -0
- package/gte.js +6 -0
- package/index.js +259 -60
- package/lt.js +6 -0
- package/lte.js +6 -0
- package/map.js +118 -45
- package/not.js +8 -0
- package/omit.js +7 -0
- package/or.js +9 -0
- package/package.json +1 -1
- package/pick.js +7 -0
- package/pipe.js +8 -0
- package/reduce.js +8 -0
- package/set.js +6 -0
- package/some.js +6 -0
- package/switchCase.js +12 -0
- package/tap.js +75 -26
- package/transform.js +38 -10
- package/tryCatch.js +14 -0
package/map.js
CHANGED
|
@@ -3,6 +3,7 @@ const MappingIterator = require('./_internal/MappingIterator')
|
|
|
3
3
|
const MappingAsyncIterator = require('./_internal/MappingAsyncIterator')
|
|
4
4
|
const __ = require('./_internal/placeholder')
|
|
5
5
|
const curry2 = require('./_internal/curry2')
|
|
6
|
+
const curry3 = require('./_internal/curry3')
|
|
6
7
|
const isArray = require('./_internal/isArray')
|
|
7
8
|
const isObject = require('./_internal/isObject')
|
|
8
9
|
const arrayMap = require('./_internal/arrayMap')
|
|
@@ -16,6 +17,10 @@ const objectMapSeries = require('./_internal/objectMapSeries')
|
|
|
16
17
|
const setMapSeries = require('./_internal/setMapSeries')
|
|
17
18
|
const mapMapSeries = require('./_internal/mapMapSeries')
|
|
18
19
|
const arrayMapPool = require('./_internal/arrayMapPool')
|
|
20
|
+
const stringMapPool = require('./_internal/stringMapPool')
|
|
21
|
+
const setMapPool = require('./_internal/setMapPool')
|
|
22
|
+
const mapMapPool = require('./_internal/mapMapPool')
|
|
23
|
+
const objectMapPool = require('./_internal/objectMapPool')
|
|
19
24
|
const objectMapEntries = require('./_internal/objectMapEntries')
|
|
20
25
|
const mapMapEntries = require('./_internal/mapMapEntries')
|
|
21
26
|
const symbolIterator = require('./_internal/symbolIterator')
|
|
@@ -45,21 +50,6 @@ const symbolAsyncIterator = require('./_internal/symbolAsyncIterator')
|
|
|
45
50
|
* originalMap Map,
|
|
46
51
|
* mapMapper (value any, key any, originalMap Map)=>Promise|any
|
|
47
52
|
* ) -> mappedMap Promise|Map
|
|
48
|
-
*
|
|
49
|
-
* _map(
|
|
50
|
-
* generatorFunction ...args=>Generator,
|
|
51
|
-
* syncMapper (value any)=>any,
|
|
52
|
-
* ) -> mappingGeneratorFunction ...args=>Generator
|
|
53
|
-
*
|
|
54
|
-
* _map(
|
|
55
|
-
* asyncGeneratorFunction ...args=>AsyncGenerator,
|
|
56
|
-
* mapper (value any)=>Promise|any
|
|
57
|
-
* ) -> mappingAsyncGeneratorFunction ...args=>AsyncGenerator
|
|
58
|
-
*
|
|
59
|
-
* _map(
|
|
60
|
-
* originalReducer Reducer,
|
|
61
|
-
* mapper (value any)=>Promise|any,
|
|
62
|
-
* ) -> mappingReducer Reducer
|
|
63
53
|
* ```
|
|
64
54
|
*/
|
|
65
55
|
|
|
@@ -107,11 +97,11 @@ const _map = function (value, mapper) {
|
|
|
107
97
|
*
|
|
108
98
|
* type Mapper = (
|
|
109
99
|
* value any,
|
|
110
|
-
* indexOrKey number|string,
|
|
100
|
+
* indexOrKey number|string|any,
|
|
111
101
|
* collection Mappable
|
|
112
102
|
* )=>(resultItem Promise|any)
|
|
113
103
|
*
|
|
114
|
-
* map(collection Mappable, f Mapper) -> result Promise|Mappable
|
|
104
|
+
* map(collection Promise|Mappable, f Mapper) -> result Promise|Mappable
|
|
115
105
|
* map(f Mapper)(collection Mappable) -> result Promise|Mappable
|
|
116
106
|
* ```
|
|
117
107
|
*
|
|
@@ -246,12 +236,21 @@ const _map = function (value, mapper) {
|
|
|
246
236
|
* })()
|
|
247
237
|
* ```
|
|
248
238
|
*
|
|
239
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
240
|
+
*
|
|
241
|
+
* ```javascript [playground]
|
|
242
|
+
* const asyncSquare = async n => n ** 2
|
|
243
|
+
*
|
|
244
|
+
* map(Promise.resolve([1, 2, 3, 4, 5]), asyncSquare).then(console.log)
|
|
245
|
+
* // [1, 4, 9, 16, 25]
|
|
246
|
+
* ```
|
|
247
|
+
*
|
|
249
248
|
* @execution concurrent
|
|
250
249
|
*
|
|
251
250
|
* @TODO streamMap
|
|
252
251
|
*/
|
|
253
252
|
const map = function (arg0, arg1) {
|
|
254
|
-
if (
|
|
253
|
+
if (arg1 == null) {
|
|
255
254
|
return curry2(_map, __, arg0)
|
|
256
255
|
}
|
|
257
256
|
return isPromise(arg0)
|
|
@@ -278,14 +277,19 @@ const _mapEntries = (value, mapper) => {
|
|
|
278
277
|
*
|
|
279
278
|
* @synopsis
|
|
280
279
|
* ```coffeescript [specscript]
|
|
281
|
-
*
|
|
282
|
-
* value Map|Object|Promise<Map|Object>,
|
|
283
|
-
* mapper ([key any, value any])=>Promise|[any, any],
|
|
284
|
-
* ) -> Promise|Map|Object
|
|
280
|
+
* type EntriesMappable = Object|Map
|
|
285
281
|
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
282
|
+
* type Mapper = (
|
|
283
|
+
* value any,
|
|
284
|
+
* key string|any,
|
|
285
|
+
* collection EntriesMappable
|
|
286
|
+
* )=>(resultItem Promise|any)
|
|
287
|
+
*
|
|
288
|
+
* map.entries(value Promise|EntriesMappable, mapper Mapper)
|
|
289
|
+
* -> Promise|EntriesMappable
|
|
290
|
+
*
|
|
291
|
+
* map.entries(mapper Mapper)(value EntriesMappable)
|
|
292
|
+
* -> Promise|EntriesMappable
|
|
289
293
|
* ```
|
|
290
294
|
*
|
|
291
295
|
* @description
|
|
@@ -302,10 +306,22 @@ const _mapEntries = (value, mapper) => {
|
|
|
302
306
|
* // Map(3) { 'A' => 1, 'B' => 4, 'C' => 9 }
|
|
303
307
|
* ```
|
|
304
308
|
*
|
|
309
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
310
|
+
*
|
|
311
|
+
* ```javascript [playground]
|
|
312
|
+
* const asyncSquareEntries = async ([k, v]) => [k, v ** 2]
|
|
313
|
+
*
|
|
314
|
+
* map.entries(
|
|
315
|
+
* Promise.resolve({ a: 1, b: 2, c: 3 }),
|
|
316
|
+
* asyncSquareEntries,
|
|
317
|
+
* ).then(console.log)
|
|
318
|
+
* // { a: 1, b: 4, c: 9 }
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
305
321
|
* @since v1.7.0
|
|
306
322
|
*/
|
|
307
323
|
map.entries = function mapEntries(arg0, arg1) {
|
|
308
|
-
if (
|
|
324
|
+
if (arg1 == null) {
|
|
309
325
|
return curry2(_mapEntries, __, arg0)
|
|
310
326
|
}
|
|
311
327
|
return isPromise(arg0)
|
|
@@ -318,11 +334,11 @@ map.entries = function mapEntries(arg0, arg1) {
|
|
|
318
334
|
*
|
|
319
335
|
* @synopsis
|
|
320
336
|
* ```coffeescript [specscript]
|
|
321
|
-
* type Mappable = Array|Object|Set|Map
|
|
337
|
+
* type Mappable = Array|Object|Set|Map
|
|
322
338
|
*
|
|
323
339
|
* type Mapper = (
|
|
324
340
|
* value any,
|
|
325
|
-
* indexOrKey number|string,
|
|
341
|
+
* indexOrKey number|string|any,
|
|
326
342
|
* collection Mappable
|
|
327
343
|
* )=>(mappedItem Promise|any)
|
|
328
344
|
*
|
|
@@ -357,23 +373,20 @@ const _mapSeries = function (collection, f) {
|
|
|
357
373
|
*
|
|
358
374
|
* @synopsis
|
|
359
375
|
* ```coffeescript [specscript]
|
|
360
|
-
* type Mappable = Array|Object|Set|Map
|
|
376
|
+
* type Mappable = Array|Object|Set|Map
|
|
361
377
|
*
|
|
362
378
|
* type Mapper = (
|
|
363
379
|
* value any,
|
|
364
|
-
* indexOrKey number|string,
|
|
380
|
+
* indexOrKey number|string|any,
|
|
365
381
|
* collection Mappable
|
|
366
382
|
* )=>(mappedItem Promise|any)
|
|
367
383
|
*
|
|
368
|
-
* map.series( Mappable)
|
|
369
|
-
*
|
|
370
|
-
* map.series(
|
|
371
|
-
* mapperFunc (value any)=>Promise|any,
|
|
372
|
-
* )(array Array) -> Promise|Array
|
|
384
|
+
* map.series(collection Promise|Mappable, f Mapper) -> result Mappable
|
|
385
|
+
* map.series(f Mapper)(collection Mappable) -> result Mappable
|
|
373
386
|
* ```
|
|
374
387
|
*
|
|
375
388
|
* @description
|
|
376
|
-
*
|
|
389
|
+
* [map](/docs/map) with serial execution.
|
|
377
390
|
*
|
|
378
391
|
* ```javascript [playground]
|
|
379
392
|
* const delayedLog = number => new Promise(function (resolve) {
|
|
@@ -384,13 +397,22 @@ const _mapSeries = function (collection, f) {
|
|
|
384
397
|
* })
|
|
385
398
|
*
|
|
386
399
|
* console.log('start')
|
|
387
|
-
* map.series(
|
|
400
|
+
* map.series([1, 2, 3, 4, 5], delayedLog)
|
|
401
|
+
* ```
|
|
402
|
+
*
|
|
403
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
404
|
+
*
|
|
405
|
+
* ```javascript [playground]
|
|
406
|
+
* const asyncSquare = async n => n ** 2
|
|
407
|
+
*
|
|
408
|
+
* map.series(Promise.resolve([1, 2, 3, 4, 5]), asyncSquare).then(console.log)
|
|
409
|
+
* // [1, 4, 9, 16, 25]
|
|
388
410
|
* ```
|
|
389
411
|
*
|
|
390
412
|
* @execution series
|
|
391
413
|
*/
|
|
392
414
|
map.series = function mapSeries(arg0, arg1) {
|
|
393
|
-
if (
|
|
415
|
+
if (arg1 == null) {
|
|
394
416
|
return curry2(_mapSeries, __, arg0)
|
|
395
417
|
}
|
|
396
418
|
return isPromise(arg0)
|
|
@@ -398,19 +420,59 @@ map.series = function mapSeries(arg0, arg1) {
|
|
|
398
420
|
: _mapSeries(arg0, arg1)
|
|
399
421
|
}
|
|
400
422
|
|
|
423
|
+
/**
|
|
424
|
+
* @name _mapPool
|
|
425
|
+
*
|
|
426
|
+
* @synopsis
|
|
427
|
+
* ```coffeescript [specscript]
|
|
428
|
+
* type Mappable = Array|Object|Set|Map
|
|
429
|
+
*
|
|
430
|
+
* _mapPool(collection Mappable, concurrency number, f function) -> result Promise|Mappable
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
const _mapPool = function (collection, concurrency, f) {
|
|
434
|
+
if (isArray(collection)) {
|
|
435
|
+
return arrayMapPool(collection, concurrency, f)
|
|
436
|
+
}
|
|
437
|
+
if (collection == null) {
|
|
438
|
+
throw new TypeError(`invalid collection ${collection}`)
|
|
439
|
+
}
|
|
440
|
+
if (typeof collection == 'string' || collection.constructor == String) {
|
|
441
|
+
return stringMapPool(collection, concurrency, f)
|
|
442
|
+
}
|
|
443
|
+
if (collection.constructor == Set) {
|
|
444
|
+
return setMapPool(collection, concurrency, f)
|
|
445
|
+
}
|
|
446
|
+
if (collection.constructor == Map) {
|
|
447
|
+
return mapMapPool(collection, concurrency, f)
|
|
448
|
+
}
|
|
449
|
+
if (collection.constructor == Object) {
|
|
450
|
+
return objectMapPool(collection, concurrency, f)
|
|
451
|
+
}
|
|
452
|
+
throw new TypeError(`invalid collection ${collection}`)
|
|
453
|
+
}
|
|
454
|
+
|
|
401
455
|
/**
|
|
402
456
|
* @name map.pool
|
|
403
457
|
*
|
|
404
458
|
* @synopsis
|
|
405
459
|
* ```coffeescript [specscript]
|
|
460
|
+
* type Mappable = Array|Object|Set|Map
|
|
461
|
+
*
|
|
462
|
+
* map.pool(
|
|
463
|
+
* concurrency number,
|
|
464
|
+
* mapper (value any)=>Promise|any,
|
|
465
|
+
* )(collection Mappable) -> result Promise|Array
|
|
466
|
+
*
|
|
406
467
|
* map.pool(
|
|
407
|
-
*
|
|
468
|
+
* collection Mappable,
|
|
469
|
+
* concurrency number,
|
|
408
470
|
* mapper (value any)=>Promise|any,
|
|
409
|
-
* )
|
|
471
|
+
* ) -> result Promise|Array
|
|
410
472
|
* ```
|
|
411
473
|
*
|
|
412
474
|
* @description
|
|
413
|
-
*
|
|
475
|
+
* [map](/docs/map) with limited [concurrency](https://web.mit.edu/6.005/www/fa14/classes/17-concurrency/).
|
|
414
476
|
*
|
|
415
477
|
* ```javascript [playground]
|
|
416
478
|
* const ids = [1, 2, 3, 4, 5]
|
|
@@ -428,15 +490,26 @@ map.series = function mapSeries(arg0, arg1) {
|
|
|
428
490
|
* ]))(ids)
|
|
429
491
|
* ```
|
|
430
492
|
*
|
|
493
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
494
|
+
*
|
|
495
|
+
* ```javascript [playground]
|
|
496
|
+
* const asyncSquare = async n => n ** 2
|
|
497
|
+
*
|
|
498
|
+
* map.pool(Promise.resolve([1, 2, 3, 4, 5]), 5, asyncSquare).then(console.log)
|
|
499
|
+
* // [1, 4, 9, 16, 25]
|
|
500
|
+
* ```
|
|
501
|
+
*
|
|
431
502
|
* @TODO objectMapPool
|
|
432
503
|
*
|
|
433
504
|
* @execution concurrent
|
|
434
505
|
*/
|
|
435
|
-
map.pool = (
|
|
436
|
-
if (
|
|
437
|
-
return
|
|
506
|
+
map.pool = function mapPool(arg0, arg1, arg2) {
|
|
507
|
+
if (arg2 == null) {
|
|
508
|
+
return curry3(_mapPool, __, arg0, arg1)
|
|
438
509
|
}
|
|
439
|
-
|
|
510
|
+
return isPromise(arg0)
|
|
511
|
+
? arg0.then(curry3(_mapPool, __, arg1, arg2))
|
|
512
|
+
: _mapPool(arg0, arg1, arg2)
|
|
440
513
|
}
|
|
441
514
|
|
|
442
515
|
module.exports = map
|
package/not.js
CHANGED
|
@@ -45,6 +45,14 @@ const _not = function (args, predicate) {
|
|
|
45
45
|
* not(isOdd)(3),
|
|
46
46
|
* ) // false
|
|
47
47
|
* ```
|
|
48
|
+
*
|
|
49
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
50
|
+
*
|
|
51
|
+
* ```javascript [playground]
|
|
52
|
+
* const isOdd = number => number % 2 == 1
|
|
53
|
+
*
|
|
54
|
+
* not(Promise.resolve(3), isOdd).then(console.log) // false
|
|
55
|
+
* ```
|
|
48
56
|
*/
|
|
49
57
|
|
|
50
58
|
const not = function (...args) {
|
package/omit.js
CHANGED
|
@@ -62,6 +62,13 @@ const _omit = function (source, paths) {
|
|
|
62
62
|
* console.log, // { c: 9 }
|
|
63
63
|
* ])
|
|
64
64
|
* ```
|
|
65
|
+
*
|
|
66
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
67
|
+
*
|
|
68
|
+
* ```javascript [playground]
|
|
69
|
+
* omit(Promise.resolve({ a: 1, b: 2, c: 3 }), ['a', 'b']).then(console.log)
|
|
70
|
+
* // { c: 3 }
|
|
71
|
+
* ```
|
|
65
72
|
*/
|
|
66
73
|
const omit = function (arg0, arg1) {
|
|
67
74
|
if (arg1 == null) {
|
package/or.js
CHANGED
|
@@ -129,6 +129,15 @@ const areAnyPredicatesTruthy = function (args, predicates) {
|
|
|
129
129
|
* ) // true
|
|
130
130
|
* ```
|
|
131
131
|
*
|
|
132
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
133
|
+
*
|
|
134
|
+
* ```javascript [playground]
|
|
135
|
+
* or(Promise.resolve('aaa'), [
|
|
136
|
+
* s => s.startsWith('b'),
|
|
137
|
+
* s => s.endsWith('a'),
|
|
138
|
+
* ]).then(console.log) // true
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
132
141
|
* @execution series
|
|
133
142
|
*
|
|
134
143
|
* @note ...args slows down here by an order of magnitude
|
package/package.json
CHANGED
package/pick.js
CHANGED
|
@@ -62,6 +62,13 @@ const _pick = function (source, keys) {
|
|
|
62
62
|
* console.log, // { a: 1, c: 9 }
|
|
63
63
|
* ])
|
|
64
64
|
* ```
|
|
65
|
+
*
|
|
66
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
67
|
+
*
|
|
68
|
+
* ```javascript [playground]
|
|
69
|
+
* pick(Promise.resolve({ a: 1, b: 2, c: 3 }), ['a', 'b']).then(console.log)
|
|
70
|
+
* // { a: 1, b: 2 }
|
|
71
|
+
* ```
|
|
65
72
|
*/
|
|
66
73
|
const pick = function (arg0, arg1) {
|
|
67
74
|
if (arg1 == null) {
|
package/pipe.js
CHANGED
|
@@ -46,6 +46,14 @@ const __ = require('./_internal/placeholder')
|
|
|
46
46
|
* ])
|
|
47
47
|
* ```
|
|
48
48
|
*
|
|
49
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
50
|
+
*
|
|
51
|
+
* ```javascript [playground]
|
|
52
|
+
* pipe(Promise.resolve(1), 2, Promise.resolve(3), [
|
|
53
|
+
* console.log, // [1, 2, 3]
|
|
54
|
+
* ])
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
49
57
|
* @execution series
|
|
50
58
|
*
|
|
51
59
|
* @transducing
|
package/reduce.js
CHANGED
|
@@ -172,6 +172,14 @@ const _reduce = function (collection, reducer, initialValue) {
|
|
|
172
172
|
* reduce(asyncAdd)(asyncGenerate12345()).then(console.log) // 15
|
|
173
173
|
* ```
|
|
174
174
|
*
|
|
175
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
176
|
+
*
|
|
177
|
+
* ```javascript [playground]
|
|
178
|
+
* const add = (a, b) => a + b
|
|
179
|
+
*
|
|
180
|
+
* reduce(Promise.resolve([1, 2, 3, 4, 5]), add, 0).then(console.log) // 15
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
175
183
|
* @execution series
|
|
176
184
|
*
|
|
177
185
|
* @transducing
|
package/set.js
CHANGED
|
@@ -90,6 +90,12 @@ const _set = function (obj, path, value) {
|
|
|
90
90
|
* ])
|
|
91
91
|
* ```
|
|
92
92
|
*
|
|
93
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
94
|
+
*
|
|
95
|
+
* ```javascript [playground]
|
|
96
|
+
* set(Promise.resolve({}), 'a', 1).then(console.log) // { a: 1 }
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
93
99
|
* @since 1.7.0
|
|
94
100
|
*/
|
|
95
101
|
|
package/some.js
CHANGED
|
@@ -92,6 +92,12 @@ const _some = function (collection, predicate) {
|
|
|
92
92
|
* ])
|
|
93
93
|
* ```
|
|
94
94
|
*
|
|
95
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
96
|
+
*
|
|
97
|
+
* ```javascript [playground]
|
|
98
|
+
* some(Promise.resolve([1, 2, 3, 4, 5]), n => n > 6).then(console.log) // false
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
95
101
|
* @execution concurrent
|
|
96
102
|
*
|
|
97
103
|
* @muxing
|
package/switchCase.js
CHANGED
|
@@ -79,6 +79,18 @@ const curryArgs3 = require('./_internal/curryArgs3')
|
|
|
79
79
|
* console.log(myDrink) // Beer
|
|
80
80
|
* ```
|
|
81
81
|
*
|
|
82
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
83
|
+
*
|
|
84
|
+
* ```javascript [playground]
|
|
85
|
+
* switchCase(Promise.resolve(1), 2, Promise.resolve(3), [
|
|
86
|
+
* function doValuesAddUpTo6(a, b, c) {
|
|
87
|
+
* return a + b + c == 6
|
|
88
|
+
* },
|
|
89
|
+
* (a, b, c) => console.log(`${a} + ${b} + ${c} == 6`),
|
|
90
|
+
* (a, b, c) => console.log(`${a} + ${b} + ${c} != 6`),
|
|
91
|
+
* ]) // 1 + 2 + 3 == 6
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
82
94
|
* @execution series
|
|
83
95
|
*/
|
|
84
96
|
const switchCase = (...args) => {
|
package/tap.js
CHANGED
|
@@ -2,14 +2,18 @@ const isPromise = require('./_internal/isPromise')
|
|
|
2
2
|
const always = require('./_internal/always')
|
|
3
3
|
const thunkifyArgs = require('./_internal/thunkifyArgs')
|
|
4
4
|
const thunkConditional = require('./_internal/thunkConditional')
|
|
5
|
+
const curry2 = require('./_internal/curry2')
|
|
5
6
|
const curry3 = require('./_internal/curry3')
|
|
6
7
|
const curryArgs2 = require('./_internal/curryArgs2')
|
|
8
|
+
const curryArgs3 = require('./_internal/curryArgs3')
|
|
7
9
|
const __ = require('./_internal/placeholder')
|
|
10
|
+
const areAnyValuesPromises = require('./_internal/areAnyValuesPromises')
|
|
11
|
+
const promiseAll = require('./_internal/promiseAll')
|
|
8
12
|
|
|
9
|
-
// _tap(args Array,
|
|
10
|
-
const _tap = function (args,
|
|
13
|
+
// _tap(args Array, f function) -> Promise|any
|
|
14
|
+
const _tap = function (args, f) {
|
|
11
15
|
const result = args[0],
|
|
12
|
-
call =
|
|
16
|
+
call = f(...args)
|
|
13
17
|
return isPromise(call) ? call.then(always(result)) : result
|
|
14
18
|
}
|
|
15
19
|
|
|
@@ -18,8 +22,8 @@ const _tap = function (args, func) {
|
|
|
18
22
|
*
|
|
19
23
|
* @synopsis
|
|
20
24
|
* ```coffeescript [specscript]
|
|
21
|
-
* tap(...args,
|
|
22
|
-
* tap(
|
|
25
|
+
* tap(...args, f function) -> Promise|args[0]
|
|
26
|
+
* tap(f function)(...args) -> Promise|args[0]
|
|
23
27
|
* ```
|
|
24
28
|
*
|
|
25
29
|
* @description
|
|
@@ -36,13 +40,53 @@ const _tap = function (args, func) {
|
|
|
36
40
|
* // 'foobar'
|
|
37
41
|
* // 'foobarbaz'
|
|
38
42
|
* ```
|
|
43
|
+
*
|
|
44
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
45
|
+
*
|
|
46
|
+
* ```javascript [playground]
|
|
47
|
+
* tap(Promise.resolve(1), Promise.resolve(2), 3, console.log) // 1 2 3
|
|
48
|
+
* ```
|
|
39
49
|
*/
|
|
40
50
|
const tap = function (...args) {
|
|
41
|
-
const
|
|
51
|
+
const f = args.pop()
|
|
42
52
|
if (args.length == 0) {
|
|
43
|
-
return curryArgs2(_tap, __,
|
|
53
|
+
return curryArgs2(_tap, __, f)
|
|
54
|
+
}
|
|
55
|
+
if (areAnyValuesPromises(args)) {
|
|
56
|
+
return promiseAll(args).then(curry2(_tap, __, f))
|
|
57
|
+
}
|
|
58
|
+
return _tap(args, f)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @name _tapIf
|
|
63
|
+
*
|
|
64
|
+
* @synopsis
|
|
65
|
+
* ```coffeescript [specscript]
|
|
66
|
+
* _tapIf(
|
|
67
|
+
* predicate function,
|
|
68
|
+
* f function,
|
|
69
|
+
* args Array,
|
|
70
|
+
* ) -> Promise|args[0]
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
const _tapIf = function (predicate, f, args) {
|
|
74
|
+
const b = predicate(...args)
|
|
75
|
+
if (isPromise(b)) {
|
|
76
|
+
return b.then(curry3(
|
|
77
|
+
thunkConditional,
|
|
78
|
+
__,
|
|
79
|
+
thunkifyArgs(tap(f), args),
|
|
80
|
+
always(args[0]),
|
|
81
|
+
))
|
|
44
82
|
}
|
|
45
|
-
|
|
83
|
+
if (b) {
|
|
84
|
+
const execution = f(...args)
|
|
85
|
+
if (isPromise(execution)) {
|
|
86
|
+
return execution.then(always(args[0]))
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return args[0]
|
|
46
90
|
}
|
|
47
91
|
|
|
48
92
|
/**
|
|
@@ -50,37 +94,42 @@ const tap = function (...args) {
|
|
|
50
94
|
*
|
|
51
95
|
* @synopsis
|
|
52
96
|
* ```coffeescript [specscript]
|
|
53
|
-
* tap.if(predicate function,
|
|
97
|
+
* tap.if(...args, predicate function, f function) -> Promise|args[0]
|
|
98
|
+
* tap.if(predicate function, f function)(...args) -> Promise|args[0]
|
|
54
99
|
* ```
|
|
55
100
|
*
|
|
56
101
|
* @description
|
|
57
|
-
* A version of `tap` that accepts a predicate function (a function that returns a boolean value) before the function to execute. Only executes
|
|
102
|
+
* A version of `tap` that accepts a predicate function (a function that returns a boolean value) before the function `f` to execute. Only executes `f` if the predicate function tests true. The arguments are the same to both the predicate function and the function to execute `f`.
|
|
58
103
|
*
|
|
59
104
|
* ```javascript [playground]
|
|
60
105
|
* const isOdd = number => number % 2 == 1
|
|
61
106
|
*
|
|
62
|
-
* const logIfOdd = tap.if(
|
|
63
|
-
* isOdd,
|
|
64
|
-
* number => console.log(number, 'is an odd number')
|
|
65
|
-
* )
|
|
107
|
+
* const logIfOdd = tap.if(isOdd, console.log)
|
|
66
108
|
*
|
|
67
109
|
* logIfOdd(2)
|
|
68
|
-
* logIfOdd(3) // 3
|
|
110
|
+
* logIfOdd(3) // 3
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
114
|
+
*
|
|
115
|
+
* ```javascript [playground]
|
|
116
|
+
* tap.if(Promise.resolve(1), n => n < 5, console.log) // 1
|
|
117
|
+
* tap.if(Promise.resolve(6), n => n < 5, console.log)
|
|
69
118
|
* ```
|
|
70
119
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
return
|
|
75
|
-
thunkConditional, __, thunkifyArgs(tap(func), args), always(args[0])))
|
|
120
|
+
|
|
121
|
+
tap.if = function (...args) {
|
|
122
|
+
if (args.length == 2) {
|
|
123
|
+
return curryArgs3(_tapIf, args[0], args[1], __)
|
|
76
124
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
125
|
+
const argsLength = args.length
|
|
126
|
+
const f = args[argsLength - 1]
|
|
127
|
+
const predicate = args[argsLength - 2]
|
|
128
|
+
const argValues = args.slice(0, -2)
|
|
129
|
+
if (areAnyValuesPromises(argValues)) {
|
|
130
|
+
return promiseAll(argValues).then(curry3(_tapIf, predicate, f, __))
|
|
82
131
|
}
|
|
83
|
-
return args
|
|
132
|
+
return _tapIf(predicate, f, args)
|
|
84
133
|
}
|
|
85
134
|
|
|
86
135
|
module.exports = tap
|
package/transform.js
CHANGED
|
@@ -115,10 +115,9 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
115
115
|
*
|
|
116
116
|
* `transform` an async generator into `process.stdout`, a Node.js writable stream that implements `.write`.
|
|
117
117
|
*
|
|
118
|
-
* ```javascript [
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* const { pipe, map, transform } = require('rubico')
|
|
118
|
+
* ```javascript [playground]
|
|
119
|
+
* const { pipe, compose, transform } = rubico
|
|
120
|
+
* // global Transducer
|
|
122
121
|
*
|
|
123
122
|
* const square = number => number ** 2
|
|
124
123
|
*
|
|
@@ -126,17 +125,46 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
126
125
|
*
|
|
127
126
|
* const randomInt = () => Math.ceil(Math.random() * 100)
|
|
128
127
|
*
|
|
129
|
-
* const streamRandomInts = async function* () {
|
|
130
|
-
*
|
|
128
|
+
* const streamRandomInts = async function* (n) {
|
|
129
|
+
* let ct = 0
|
|
130
|
+
* while (ct < n) {
|
|
131
|
+
* ct += 1
|
|
131
132
|
* yield randomInt()
|
|
132
133
|
* }
|
|
133
134
|
* }
|
|
134
135
|
*
|
|
136
|
+
* const Stdout = {
|
|
137
|
+
* concat(...args) {
|
|
138
|
+
* console.log(...args)
|
|
139
|
+
* return this
|
|
140
|
+
* },
|
|
141
|
+
* }
|
|
142
|
+
*
|
|
143
|
+
* transform(
|
|
144
|
+
* streamRandomInts(10),
|
|
145
|
+
* compose([
|
|
146
|
+
* Transducer.map(square),
|
|
147
|
+
* Transducer.map(toString),
|
|
148
|
+
* ]),
|
|
149
|
+
* Stdout,
|
|
150
|
+
* )
|
|
151
|
+
* // 8281
|
|
152
|
+
* // 8836
|
|
153
|
+
* // 1156
|
|
154
|
+
* // 8649
|
|
155
|
+
* // 5625
|
|
156
|
+
* // 2500
|
|
157
|
+
* // ...
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* 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
|
+
*
|
|
162
|
+
* ```javascript [playground]
|
|
135
163
|
* transform(
|
|
136
|
-
*
|
|
137
|
-
* Transducer.map(
|
|
138
|
-
*
|
|
139
|
-
* ) //
|
|
164
|
+
* Promise.resolve([1, 2, 3, 4, 5]),
|
|
165
|
+
* Transducer.map(n => n ** 2),
|
|
166
|
+
* [],
|
|
167
|
+
* ).then(console.log) // [1, 4, 9, 16, 25]
|
|
140
168
|
* ```
|
|
141
169
|
*
|
|
142
170
|
* @execution series
|
package/tryCatch.js
CHANGED
|
@@ -61,6 +61,20 @@ const _tryCatch = function (tryer, catcher, args) {
|
|
|
61
61
|
* console.error(error.message) // the sum is 6
|
|
62
62
|
* })
|
|
63
63
|
* ```
|
|
64
|
+
*
|
|
65
|
+
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
66
|
+
*
|
|
67
|
+
* ```javascript [playground]
|
|
68
|
+
* tryCatch(Promise.resolve(1), 2, Promise.resolve(3), (a, b, c) => {
|
|
69
|
+
* const sum = a + b + c
|
|
70
|
+
* if (sum > 5) {
|
|
71
|
+
* throw new Error('limit exceeded')
|
|
72
|
+
* }
|
|
73
|
+
* console.log('sum:', sum)
|
|
74
|
+
* }, (error, a, b, c) => {
|
|
75
|
+
* console.error(`${a} + ${b} + ${c}: ${error.message}`)
|
|
76
|
+
* })
|
|
77
|
+
* ```
|
|
64
78
|
*/
|
|
65
79
|
|
|
66
80
|
const tryCatch = function (...args) {
|