rubico 1.9.7 → 2.0.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/.eslintignore +5 -0
- package/.eslintrc.js +3 -2
- package/.github/workflows/nodejs.yml +1 -1
- package/AggregateReducer.js +19 -0
- package/AggregateReducer.test.js +82 -0
- package/CHANGELOG.md +22 -1
- package/README.md +158 -81
- package/Transducer.js +75 -26
- package/Transducer.test.js +117 -0
- package/_internal/ComparisonOperator.js +68 -0
- package/_internal/File.js +41 -0
- package/_internal/FlatMappingAsyncIterator.js +4 -4
- package/_internal/FlatMappingIterator.js +1 -1
- package/_internal/TimeInLoopSuite.js +138 -0
- package/_internal/areAnyValuesPromises.js +23 -0
- package/_internal/{arrayAll.js → arrayEvery.js} +4 -4
- package/_internal/arrayExtend.js +3 -2
- package/_internal/arrayFilter.js +3 -4
- package/_internal/{arrayAny.js → arraySome.js} +8 -8
- package/_internal/{asyncIteratorAll.js → asyncIteratorEvery.js} +4 -4
- package/_internal/{asyncIteratorAny.js → asyncIteratorSome.js} +4 -4
- package/_internal/curry4.test.js +25 -0
- package/_internal/curry5.test.js +29 -0
- package/_internal/curryArgs2.js +43 -0
- package/_internal/curryArgs3.test.js +21 -0
- package/_internal/curryArgs4.js +65 -0
- package/_internal/curryArgs4.test.js +25 -0
- package/_internal/equals.js +13 -0
- package/_internal/findAllFilePaths.js +22 -0
- package/_internal/funcApply.js +2 -0
- package/_internal/funcCall.js +14 -0
- package/_internal/functionArrayAll.js +26 -0
- package/_internal/functionArrayAllSeries.js +55 -0
- package/_internal/functionObjectAll.js +32 -0
- package/_internal/genericReduce.js +4 -22
- package/_internal/genericTransform.js +15 -15
- package/_internal/improvedGenericTransform.js +93 -0
- package/_internal/{iteratorAll.js → iteratorEvery.js} +4 -4
- package/_internal/{iteratorAny.js → iteratorSome.js} +6 -6
- package/_internal/leftResolverRightResolverCompare.js +19 -0
- package/_internal/leftResolverRightValueCompare.js +16 -0
- package/_internal/leftValueRightResolverCompare.js +16 -0
- package/_internal/objectReduce.js +0 -1
- package/_internal/pathResolve.js +6 -0
- package/_internal/{reducerAll.js → reducerEvery.js} +4 -4
- package/_internal/reducerFlatMap.js +4 -4
- package/_internal/reducerFlatten.js +1 -1
- package/_internal/{reducerAny.js → reducerSome.js} +4 -4
- package/_internal/timeInLoop.js +37 -0
- package/_internal/timeInLoop.test.js +18 -0
- package/_internal/timeInLoopAsync.js +35 -0
- package/_internal/timeInLoopAsync.test.js +22 -0
- package/all.js +106 -40
- package/and.js +54 -36
- package/archive/{FlatMappingIteratorCool.js → FlatMappingIterator-2020-09-28.js} +1 -1
- package/archive/_Promise-2023-05-29.js +93 -0
- package/archive/arrayMap2-2023-05-29.js +73 -0
- package/archive/benchmarks-v1.9.7/all.js +34 -0
- package/archive/benchmarks-v1.9.7/and.js +24 -0
- package/archive/benchmarks-v1.9.7/assign.js +174 -0
- package/archive/benchmarks-v1.9.7/curry.js +55 -0
- package/archive/benchmarks-v1.9.7/eq.js +25 -0
- package/archive/benchmarks-v1.9.7/filter.js +1322 -0
- package/archive/benchmarks-v1.9.7/flatMap.js +48 -0
- package/archive/benchmarks-v1.9.7/get.js +44 -0
- package/archive/benchmarks-v1.9.7/gt.js +25 -0
- package/archive/benchmarks-v1.9.7/gte.js +25 -0
- package/archive/benchmarks-v1.9.7/lt.js +25 -0
- package/archive/benchmarks-v1.9.7/lte.js +25 -0
- package/archive/benchmarks-v1.9.7/map.js +892 -0
- package/archive/benchmarks-v1.9.7/omit.js +28 -0
- package/archive/benchmarks-v1.9.7/or.js +51 -0
- package/archive/benchmarks-v1.9.7/pick.js +24 -0
- package/archive/benchmarks-v1.9.7/pipe.js +152 -0
- package/archive/benchmarks-v1.9.7/reduce.js +739 -0
- package/archive/benchmarks-v1.9.7/switchCase.js +256 -0
- package/archive/benchmarks-v1.9.7/tap.js +90 -0
- package/archive/benchmarks-v1.9.7/transform.js +218 -0
- package/archive/benchmarks-v1.9.7/tryCatch.js +108 -0
- package/assign.js +18 -8
- package/bench +65 -0
- package/benchmark-output/v1.9.7 +268 -0
- package/benchmarks/all.async.js +43 -0
- package/benchmarks/all.js +42 -33
- package/benchmarks/always.js +15 -0
- package/benchmarks/and.async.js +25 -0
- package/benchmarks/and.js +20 -19
- package/benchmarks/assign.async.js +27 -0
- package/benchmarks/assign.js +20 -167
- package/benchmarks/curry.js +34 -54
- package/benchmarks/eq.async.js +23 -0
- package/benchmarks/eq.js +17 -19
- package/benchmarks/every.async.js +19 -0
- package/benchmarks/every.js +19 -0
- package/benchmarks/filter.async.js +32 -0
- package/benchmarks/filter.js +27 -1311
- package/benchmarks/flatMap.async.js +26 -0
- package/benchmarks/flatMap.js +26 -36
- package/benchmarks/get.async.js +19 -0
- package/benchmarks/get.js +27 -32
- package/benchmarks/gt.async.js +23 -0
- package/benchmarks/gt.js +17 -19
- package/benchmarks/gte.async.js +23 -0
- package/benchmarks/gte.js +17 -19
- package/benchmarks/lt.async.js +23 -0
- package/benchmarks/lt.js +17 -19
- package/benchmarks/lte.async.js +23 -0
- package/benchmarks/lte.js +17 -19
- package/benchmarks/map.async.js +43 -0
- package/benchmarks/map.js +24 -876
- package/benchmarks/misc/Promise.js +26 -0
- package/benchmarks/misc/isPromise.js +30 -0
- package/benchmarks/misc/promiseAll.js +36 -0
- package/benchmarks/not.js +23 -0
- package/benchmarks/omit.js +30 -20
- package/benchmarks/or.async.js +25 -0
- package/benchmarks/or.js +23 -49
- package/benchmarks/pick.js +30 -16
- package/benchmarks/pipe.async.js +47 -0
- package/benchmarks/pipe.js +46 -151
- package/benchmarks/reduce.async.js +32 -0
- package/benchmarks/reduce.js +27 -728
- package/benchmarks/set.async.js +19 -0
- package/benchmarks/set.js +41 -0
- package/benchmarks/some.async.js +19 -0
- package/benchmarks/some.js +19 -0
- package/benchmarks/switchCase.async.js +27 -0
- package/benchmarks/switchCase.js +55 -256
- package/benchmarks/tap.js +10 -85
- package/benchmarks/thunkify.js +15 -0
- package/benchmarks/transform.async.js +27 -0
- package/benchmarks/transform.js +28 -206
- package/benchmarks/tryCatch.async.js +25 -0
- package/benchmarks/tryCatch.js +24 -100
- package/build +472 -0
- package/compose.js +46 -0
- package/dist/Transducer.es.js +481 -0
- package/dist/Transducer.es.min.js +7 -0
- package/dist/Transducer.js +488 -0
- package/dist/Transducer.min.js +8 -0
- package/dist/Transducer.mjs +481 -0
- 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 +173 -92
- package/dist/all.es.min.js +3 -3
- package/dist/all.js +173 -92
- package/dist/all.min.js +3 -3
- package/dist/all.mjs +173 -92
- 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 +101 -32
- package/dist/and.es.min.js +3 -3
- package/dist/and.js +101 -32
- package/dist/and.min.js +3 -3
- package/dist/and.mjs +101 -32
- package/dist/assign.es.js +37 -10
- package/dist/assign.es.min.js +3 -3
- package/dist/assign.js +37 -10
- package/dist/assign.min.js +3 -3
- package/dist/assign.mjs +37 -10
- package/dist/compose.es.js +71 -0
- package/dist/compose.es.min.js +7 -0
- package/dist/compose.js +78 -0
- package/dist/compose.min.js +8 -0
- package/dist/compose.mjs +71 -0
- 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 +172 -49
- package/dist/eq.es.min.js +3 -3
- package/dist/eq.js +172 -49
- package/dist/eq.min.js +3 -3
- package/dist/eq.mjs +172 -49
- package/dist/every.es.js +194 -0
- package/dist/every.es.min.js +7 -0
- package/dist/every.js +201 -0
- package/dist/every.min.js +8 -0
- package/dist/every.mjs +194 -0
- package/dist/filter.es.js +14 -108
- package/dist/filter.es.min.js +3 -3
- package/dist/filter.js +14 -108
- package/dist/filter.min.js +3 -3
- package/dist/filter.mjs +14 -108
- package/dist/flatMap.es.js +27 -214
- package/dist/flatMap.es.min.js +3 -3
- package/dist/flatMap.js +27 -214
- package/dist/flatMap.min.js +3 -3
- package/dist/flatMap.mjs +27 -214
- package/dist/{x/forEach.es.js → forEach.es.js} +52 -70
- package/dist/forEach.es.min.js +7 -0
- package/dist/{x/forEach.js → forEach.js} +52 -70
- package/dist/forEach.min.js +8 -0
- package/dist/{x/forEach.mjs → forEach.mjs} +52 -70
- package/dist/get.es.js +60 -5
- package/dist/get.es.min.js +3 -3
- package/dist/get.js +60 -5
- package/dist/get.min.js +3 -3
- package/dist/get.mjs +60 -5
- package/dist/gt.es.js +171 -48
- package/dist/gt.es.min.js +3 -3
- package/dist/gt.js +171 -48
- package/dist/gt.min.js +3 -3
- package/dist/gt.mjs +171 -48
- package/dist/gte.es.js +171 -48
- package/dist/gte.es.min.js +3 -3
- package/dist/gte.js +171 -48
- package/dist/gte.min.js +3 -3
- package/dist/gte.mjs +171 -48
- package/dist/lt.es.js +171 -48
- package/dist/lt.es.min.js +3 -3
- package/dist/lt.js +171 -48
- package/dist/lt.min.js +3 -3
- package/dist/lt.mjs +171 -48
- package/dist/lte.es.js +171 -48
- package/dist/lte.es.min.js +3 -3
- package/dist/lte.js +171 -48
- package/dist/lte.min.js +3 -3
- package/dist/lte.mjs +171 -48
- package/dist/map.es.js +12 -101
- package/dist/map.es.min.js +3 -3
- package/dist/map.js +12 -101
- package/dist/map.min.js +3 -3
- package/dist/map.mjs +12 -101
- package/dist/not.es.js +75 -14
- package/dist/not.es.min.js +3 -3
- package/dist/not.js +75 -14
- package/dist/not.min.js +3 -3
- package/dist/not.mjs +75 -14
- package/dist/omit.es.js +7 -2
- package/dist/omit.es.min.js +3 -3
- package/dist/omit.js +7 -2
- package/dist/omit.min.js +3 -3
- package/dist/omit.mjs +7 -2
- package/dist/or.es.js +99 -31
- package/dist/or.es.min.js +3 -3
- package/dist/or.js +99 -31
- package/dist/or.min.js +3 -3
- package/dist/or.mjs +99 -31
- package/dist/pick.es.js +8 -3
- package/dist/pick.es.min.js +3 -3
- package/dist/pick.js +8 -3
- package/dist/pick.min.js +3 -3
- package/dist/pick.mjs +8 -3
- package/dist/pipe.es.js +42 -46
- package/dist/pipe.es.min.js +3 -3
- package/dist/pipe.js +42 -46
- package/dist/pipe.min.js +3 -3
- package/dist/pipe.mjs +42 -46
- package/dist/reduce.es.js +52 -94
- package/dist/reduce.es.min.js +3 -3
- package/dist/reduce.js +52 -94
- package/dist/reduce.min.js +3 -3
- package/dist/reduce.mjs +52 -94
- package/dist/rubico.es.js +762 -883
- package/dist/rubico.es.min.js +3 -3
- package/dist/rubico.global.js +2794 -0
- package/dist/rubico.global.min.js +8 -0
- package/dist/rubico.js +739 -869
- package/dist/rubico.min.js +3 -3
- package/dist/rubico.mjs +762 -883
- package/dist/set.es.js +18 -3
- package/dist/set.es.min.js +3 -3
- package/dist/set.js +18 -3
- package/dist/set.min.js +3 -3
- package/dist/set.mjs +18 -3
- package/dist/{any.js → some.es.js} +64 -54
- package/dist/some.es.min.js +7 -0
- package/dist/{any.mjs → some.js} +72 -48
- package/dist/some.min.js +8 -0
- package/dist/{any.es.js → some.mjs} +65 -48
- package/dist/switchCase.es.js +55 -5
- package/dist/switchCase.es.min.js +3 -3
- package/dist/switchCase.js +55 -5
- package/dist/switchCase.min.js +3 -3
- package/dist/switchCase.mjs +55 -5
- package/dist/tap.es.js +2 -9
- package/dist/tap.es.min.js +3 -3
- package/dist/tap.js +2 -9
- package/dist/tap.min.js +3 -3
- package/dist/tap.mjs +2 -9
- package/dist/thunkify.es.js +45 -2
- package/dist/thunkify.es.min.js +3 -3
- package/dist/thunkify.js +45 -2
- package/dist/thunkify.min.js +3 -3
- package/dist/thunkify.mjs +45 -2
- package/dist/transform.es.js +35 -71
- package/dist/transform.es.min.js +3 -3
- package/dist/transform.js +35 -71
- package/dist/transform.min.js +3 -3
- package/dist/transform.mjs +35 -71
- package/dist/tryCatch.es.js +33 -17
- package/dist/tryCatch.es.min.js +3 -3
- package/dist/tryCatch.js +33 -17
- package/dist/tryCatch.min.js +3 -3
- package/dist/tryCatch.mjs +33 -17
- 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 +7 -7
- package/dist/x/differenceWith.es.min.js +3 -3
- package/dist/x/differenceWith.js +7 -7
- package/dist/x/differenceWith.min.js +2 -2
- package/dist/x/differenceWith.mjs +7 -7
- package/dist/x/filterOut.es.js +60 -117
- package/dist/x/filterOut.es.min.js +3 -3
- package/dist/x/filterOut.js +60 -117
- package/dist/x/filterOut.min.js +3 -3
- package/dist/x/filterOut.mjs +60 -117
- 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 +20 -207
- package/dist/x/flatten.es.min.js +3 -3
- package/dist/x/flatten.js +20 -207
- package/dist/x/flatten.min.js +3 -3
- package/dist/x/flatten.mjs +20 -207
- package/dist/x/groupBy.es.js +52 -94
- package/dist/x/groupBy.es.min.js +3 -3
- package/dist/x/groupBy.js +52 -94
- package/dist/x/groupBy.min.js +3 -3
- package/dist/x/groupBy.mjs +52 -94
- 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 +59 -6
- package/dist/x/maxBy.es.min.js +3 -3
- package/dist/x/maxBy.js +59 -6
- package/dist/x/maxBy.min.js +3 -3
- package/dist/x/maxBy.mjs +59 -6
- 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 +32 -103
- package/dist/x/pluck.es.min.js +3 -3
- package/dist/x/pluck.js +32 -103
- package/dist/x/pluck.min.js +3 -3
- package/dist/x/pluck.mjs +32 -103
- 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 -9
- package/dist/x/trace.es.min.js +3 -3
- package/dist/x/trace.js +2 -9
- package/dist/x/trace.min.js +3 -3
- package/dist/x/trace.mjs +2 -9
- 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/dist-test.js +31 -2042
- package/eq.js +21 -63
- package/es.js +739 -869
- package/every.js +94 -0
- package/filter.js +23 -91
- package/flatMap.js +75 -70
- package/forEach.js +82 -0
- package/get.js +23 -6
- package/global.js +6 -4
- package/gt.js +15 -58
- package/gte.js +14 -57
- package/index.js +739 -869
- package/lt.js +17 -60
- package/lte.js +14 -57
- package/map.js +9 -94
- package/memory-usage/reduce.js +2 -2
- package/not.js +27 -45
- package/omit.js +4 -0
- package/or.js +50 -33
- package/package.json +7 -7
- package/pick.js +5 -1
- package/pipe.js +13 -50
- package/reduce.js +42 -51
- package/rubico.js +22 -11
- package/set.js +43 -10
- package/some.js +105 -0
- package/switchCase.js +13 -3
- package/tap.js +0 -24
- package/test.js +847 -1096
- package/thunkify.js +9 -0
- package/tmp.js +1 -0
- package/transform.js +31 -16
- package/tryCatch.js +19 -15
- package/x/differenceWith.js +3 -3
- package/x/filterOut.test.js +6 -6
- package/x/flatten.js +1 -1
- package/x/flatten.test.js +0 -8
- package/x/index.js +0 -2
- package/x/pluck.js +18 -27
- package/x/pluck.test.js +3 -7
- package/x/timeInLoop.js +16 -25
- package/x/timeInLoop.test.js +8 -4
- package/any.js +0 -82
- package/dist/__.min.mjs +0 -7
- package/dist/all.min.mjs +0 -7
- package/dist/always.min.mjs +0 -7
- package/dist/and.min.mjs +0 -7
- package/dist/any.es.min.js +0 -7
- package/dist/any.min.js +0 -8
- package/dist/any.min.mjs +0 -7
- package/dist/assign.min.mjs +0 -7
- package/dist/curry.min.mjs +0 -7
- package/dist/eq.min.mjs +0 -7
- package/dist/filter.min.mjs +0 -7
- package/dist/flatMap.min.mjs +0 -7
- package/dist/fork.es.js +0 -159
- package/dist/fork.es.min.js +0 -7
- package/dist/fork.js +0 -166
- package/dist/fork.min.js +0 -8
- package/dist/fork.min.mjs +0 -7
- package/dist/fork.mjs +0 -159
- package/dist/get.min.mjs +0 -7
- package/dist/gt.min.mjs +0 -7
- package/dist/gte.min.mjs +0 -7
- package/dist/lt.min.mjs +0 -7
- package/dist/lte.min.mjs +0 -7
- package/dist/map.min.mjs +0 -7
- package/dist/not.min.mjs +0 -7
- package/dist/omit.min.mjs +0 -7
- package/dist/or.min.mjs +0 -7
- package/dist/pick.min.mjs +0 -7
- package/dist/pipe.min.mjs +0 -7
- package/dist/reduce.min.mjs +0 -7
- package/dist/rubico.min.mjs +0 -7
- package/dist/set.min.mjs +0 -7
- package/dist/switchCase.min.mjs +0 -7
- package/dist/tap.min.mjs +0 -7
- package/dist/thunkify.min.mjs +0 -7
- package/dist/transform.min.mjs +0 -7
- package/dist/tryCatch.min.mjs +0 -7
- package/dist/x/append.min.mjs +0 -7
- package/dist/x/callProp.min.mjs +0 -7
- package/dist/x/defaultsDeep.min.mjs +0 -7
- package/dist/x/differenceWith.min.mjs +0 -7
- package/dist/x/filterOut.min.mjs +0 -7
- package/dist/x/find.min.mjs +0 -7
- package/dist/x/findIndex.min.mjs +0 -7
- package/dist/x/first.min.mjs +0 -7
- package/dist/x/flatten.min.mjs +0 -7
- package/dist/x/forEach.es.min.js +0 -7
- package/dist/x/forEach.min.js +0 -8
- package/dist/x/forEach.min.mjs +0 -7
- package/dist/x/groupBy.min.mjs +0 -7
- package/dist/x/has.min.mjs +0 -7
- package/dist/x/identity.min.mjs +0 -7
- package/dist/x/includes.min.mjs +0 -7
- package/dist/x/isDeepEqual.min.mjs +0 -7
- package/dist/x/isEmpty.min.mjs +0 -7
- package/dist/x/isEqual.min.mjs +0 -7
- package/dist/x/isFunction.min.mjs +0 -7
- package/dist/x/isIn.min.mjs +0 -7
- package/dist/x/isObject.min.mjs +0 -7
- package/dist/x/isString.min.mjs +0 -7
- package/dist/x/keys.min.mjs +0 -7
- package/dist/x/last.min.mjs +0 -7
- package/dist/x/maxBy.min.mjs +0 -7
- package/dist/x/noop.min.mjs +0 -7
- package/dist/x/pluck.min.mjs +0 -7
- package/dist/x/prepend.min.mjs +0 -7
- package/dist/x/size.min.mjs +0 -7
- package/dist/x/trace.min.mjs +0 -7
- package/dist/x/unionWith.min.mjs +0 -7
- package/dist/x/uniq.min.mjs +0 -7
- package/dist/x/unless.min.mjs +0 -7
- package/dist/x/values.min.mjs +0 -7
- package/dist/x/when.min.mjs +0 -7
- package/distributor.js +0 -495
- package/fork.js +0 -101
- package/x/forEach.js +0 -93
- package/x/forEach.test.js +0 -218
- /package/{benchmarks → archive/benchmarks-v1.9.7}/any.js +0 -0
- /package/{x/forEach.benchmark.js → archive/benchmarks-v1.9.7/forEach.js} +0 -0
- /package/{benchmarks → archive/benchmarks-v1.9.7}/fork.js +0 -0
- /package/{benchmarks → archive/benchmarks-v1.9.7}/integration.js +0 -0
- /package/{benchmarks → archive/benchmarks-v1.9.7}/misc.js +0 -0
package/dist/rubico.mjs
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* rubico
|
|
2
|
+
* rubico v2.0.1
|
|
3
3
|
* https://github.com/a-synchronous/rubico
|
|
4
|
-
* (c) 2019-
|
|
4
|
+
* (c) 2019-2023 Richard Tong
|
|
5
5
|
* rubico may be freely distributed under the MIT license.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const noop = function () {}
|
|
9
|
-
|
|
10
8
|
const isPromise = value => value != null && typeof value.then == 'function'
|
|
11
9
|
|
|
10
|
+
const areAnyValuesPromises = function (values) {
|
|
11
|
+
const length = values.length
|
|
12
|
+
let index = -1
|
|
13
|
+
while (++index < length) {
|
|
14
|
+
const value = values[index]
|
|
15
|
+
if (isPromise(value)) {
|
|
16
|
+
return true
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const promiseAll = Promise.all.bind(Promise)
|
|
23
|
+
|
|
12
24
|
const funcConcat = (
|
|
13
25
|
funcA, funcB,
|
|
14
26
|
) => function pipedFunction(...args) {
|
|
@@ -18,82 +30,69 @@ const funcConcat = (
|
|
|
18
30
|
: funcB(intermediate)
|
|
19
31
|
}
|
|
20
32
|
|
|
21
|
-
const
|
|
22
|
-
funcA, funcB,
|
|
23
|
-
) => function pipedFunction(...args) {
|
|
24
|
-
return funcB(funcA(...args))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const objectProto = Object.prototype
|
|
28
|
-
|
|
29
|
-
const nativeObjectToString = objectProto.toString
|
|
33
|
+
const funcApply = (func, args) => func(...args)
|
|
30
34
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const generatorFunctionTag = '[object GeneratorFunction]'
|
|
35
|
+
const __ = Symbol.for('placeholder')
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
// argument resolver for curry2
|
|
38
|
+
const curry2ResolveArg0 = (
|
|
39
|
+
baseFunc, arg1,
|
|
40
|
+
) => function arg0Resolver(arg0) {
|
|
41
|
+
return baseFunc(arg0, arg1)
|
|
42
|
+
}
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
// argument resolver for curry2
|
|
45
|
+
const curry2ResolveArg1 = (
|
|
46
|
+
baseFunc, arg0,
|
|
47
|
+
) => function arg1Resolver(arg1) {
|
|
48
|
+
return baseFunc(arg0, arg1)
|
|
49
|
+
}
|
|
38
50
|
|
|
39
|
-
const
|
|
51
|
+
const curry2 = function (baseFunc, arg0, arg1) {
|
|
52
|
+
return arg0 == __
|
|
53
|
+
? curry2ResolveArg0(baseFunc, arg1)
|
|
54
|
+
: curry2ResolveArg1(baseFunc, arg0)
|
|
55
|
+
}
|
|
40
56
|
|
|
41
57
|
const pipe = function (...args) {
|
|
42
58
|
const funcs = args.pop()
|
|
59
|
+
const pipeline = funcs.reduce(funcConcat)
|
|
43
60
|
|
|
44
|
-
if (args.length
|
|
45
|
-
return
|
|
61
|
+
if (args.length == 0) {
|
|
62
|
+
return pipeline
|
|
46
63
|
}
|
|
47
64
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return function pipeline(...args) {
|
|
51
|
-
const firstArg = args[0]
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
typeof firstArg == 'function'
|
|
55
|
-
&& !isGeneratorFunction(firstArg)
|
|
56
|
-
&& !isAsyncGeneratorFunction(firstArg)
|
|
57
|
-
) {
|
|
58
|
-
if (functionComposition == noop) {
|
|
59
|
-
functionComposition = funcs.reduceRight(funcConcat)
|
|
60
|
-
}
|
|
61
|
-
return functionComposition(firstArg)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (functionPipeline == noop) {
|
|
65
|
-
functionPipeline = funcs.reduce(funcConcat)
|
|
66
|
-
}
|
|
67
|
-
return functionPipeline(...args)
|
|
65
|
+
if (areAnyValuesPromises(args)) {
|
|
66
|
+
return promiseAll(args).then(curry2(funcApply, pipeline, __))
|
|
68
67
|
}
|
|
69
|
-
}
|
|
70
68
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
pipe.sync = pipeSync
|
|
69
|
+
return pipeline(...args)
|
|
70
|
+
}
|
|
75
71
|
|
|
76
|
-
const
|
|
72
|
+
const compose = function (...args) {
|
|
73
|
+
const funcs = args.pop()
|
|
74
|
+
const composition = funcs.reduceRight(funcConcat)
|
|
77
75
|
|
|
78
|
-
|
|
76
|
+
if (args.length == 0) {
|
|
77
|
+
return composition
|
|
78
|
+
}
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
result = Array(funcsLength)
|
|
83
|
-
let funcsIndex = -1, isAsync = false
|
|
84
|
-
while (++funcsIndex < funcsLength) {
|
|
85
|
-
const resultItem = funcs[funcsIndex](...args)
|
|
86
|
-
if (isPromise(resultItem)) {
|
|
87
|
-
isAsync = true
|
|
88
|
-
}
|
|
89
|
-
result[funcsIndex] = resultItem
|
|
80
|
+
if (areAnyValuesPromises(args)) {
|
|
81
|
+
return promiseAll(args).then(curry2(funcApply, composition, __))
|
|
90
82
|
}
|
|
91
|
-
|
|
83
|
+
|
|
84
|
+
return composition(...args)
|
|
92
85
|
}
|
|
93
86
|
|
|
94
87
|
const always = value => function getter() { return value }
|
|
95
88
|
|
|
96
|
-
const
|
|
89
|
+
const thunkifyArgs = (func, args) => function thunk() {
|
|
90
|
+
return func(...args)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const thunkConditional = (
|
|
94
|
+
conditionalExpression, thunkOnTruthy, thunkOnFalsy,
|
|
95
|
+
) => conditionalExpression ? thunkOnTruthy() : thunkOnFalsy()
|
|
97
96
|
|
|
98
97
|
// argument resolver for curry3
|
|
99
98
|
const curry3ResolveArg0 = (
|
|
@@ -126,22 +125,62 @@ const curry3 = function (baseFunc, arg0, arg1, arg2) {
|
|
|
126
125
|
return curry3ResolveArg2(baseFunc, arg0, arg1)
|
|
127
126
|
}
|
|
128
127
|
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
const tap = func => function tapping(...args) {
|
|
129
|
+
const result = args[0],
|
|
130
|
+
call = func(...args)
|
|
131
|
+
return isPromise(call) ? call.then(always(result)) : result
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
tap.if = (predicate, func) => function tappingIf(...args) {
|
|
135
|
+
const predication = predicate(...args)
|
|
136
|
+
if (isPromise(predication)) {
|
|
137
|
+
return predication.then(curry3(
|
|
138
|
+
thunkConditional, __, thunkifyArgs(tap(func), args), always(args[0])))
|
|
139
|
+
}
|
|
140
|
+
if (predication) {
|
|
141
|
+
const execution = func(...args)
|
|
142
|
+
if (isPromise(execution)) {
|
|
143
|
+
return execution.then(always(args[0]))
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return args[0]
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const isArray = Array.isArray
|
|
150
|
+
|
|
151
|
+
// argument resolver for curryArgs2
|
|
152
|
+
const curryArgs2ResolveArgs0 = (
|
|
153
|
+
baseFunc, arg1, arg2,
|
|
154
|
+
) => function args0Resolver(...args) {
|
|
155
|
+
return baseFunc(args, arg1)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// argument resolver for curryArgs2
|
|
159
|
+
const curryArgs2ResolveArgs1 = (
|
|
160
|
+
baseFunc, arg0, arg2,
|
|
161
|
+
) => function arg1Resolver(...args) {
|
|
162
|
+
return baseFunc(arg0, args)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const curryArgs2 = function (baseFunc, arg0, arg1) {
|
|
166
|
+
if (arg0 == __) {
|
|
167
|
+
return curryArgs2ResolveArgs0(baseFunc, arg1)
|
|
168
|
+
}
|
|
169
|
+
return curryArgs2ResolveArgs1(baseFunc, arg0)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const functionArrayAll = function (funcs, args) {
|
|
173
|
+
const funcsLength = funcs.length,
|
|
174
|
+
result = Array(funcsLength)
|
|
175
|
+
let funcsIndex = -1, isAsync = false
|
|
176
|
+
while (++funcsIndex < funcsLength) {
|
|
177
|
+
const resultItem = funcs[funcsIndex](...args)
|
|
138
178
|
if (isPromise(resultItem)) {
|
|
139
|
-
|
|
140
|
-
} else {
|
|
141
|
-
result[key] = resultItem
|
|
179
|
+
isAsync = true
|
|
142
180
|
}
|
|
181
|
+
result[funcsIndex] = resultItem
|
|
143
182
|
}
|
|
144
|
-
return
|
|
183
|
+
return isAsync ? promiseAll(result) : result
|
|
145
184
|
}
|
|
146
185
|
|
|
147
186
|
// argument resolver for curry4
|
|
@@ -185,7 +224,12 @@ const curry4 = function (baseFunc, arg0, arg1, arg2, arg3) {
|
|
|
185
224
|
return curry4ResolveArg3(baseFunc, arg0, arg1, arg2)
|
|
186
225
|
}
|
|
187
226
|
|
|
188
|
-
const
|
|
227
|
+
const objectSet = function (object, property, value) {
|
|
228
|
+
object[property] = value
|
|
229
|
+
return object
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const asyncFunctionArrayAllSeries = async function (funcs, args, result, funcsIndex) {
|
|
189
233
|
const funcsLength = funcs.length
|
|
190
234
|
while (++funcsIndex < funcsLength) {
|
|
191
235
|
const resultItem = funcs[funcsIndex](...args)
|
|
@@ -194,7 +238,7 @@ const asyncFuncAllSeries = async function (funcs, args, result, funcsIndex) {
|
|
|
194
238
|
return result
|
|
195
239
|
}
|
|
196
240
|
|
|
197
|
-
const
|
|
241
|
+
const functionArrayAllSeries = function (funcs, args) {
|
|
198
242
|
const funcsLength = funcs.length, result = []
|
|
199
243
|
let funcsIndex = -1
|
|
200
244
|
while (++funcsIndex < funcsLength) {
|
|
@@ -202,94 +246,106 @@ const funcAllSeries = funcs => function allFuncsSeries(...args) {
|
|
|
202
246
|
if (isPromise(resultItem)) {
|
|
203
247
|
return resultItem.then(funcConcat(
|
|
204
248
|
curry3(objectSet, result, funcsIndex, __),
|
|
205
|
-
curry4(
|
|
249
|
+
curry4(asyncFunctionArrayAllSeries, funcs, args, __, funcsIndex)))
|
|
206
250
|
}
|
|
207
251
|
result[funcsIndex] = resultItem
|
|
208
252
|
}
|
|
209
253
|
return result
|
|
210
254
|
}
|
|
211
255
|
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
256
|
+
const functionObjectAll = function (funcs, args) {
|
|
257
|
+
const result = {}, promises = []
|
|
258
|
+
for (const key in funcs) {
|
|
259
|
+
const resultItem = funcs[key](...args)
|
|
260
|
+
if (isPromise(resultItem)) {
|
|
261
|
+
promises.push(resultItem.then(curry3(objectSet, result, key, __)))
|
|
262
|
+
} else {
|
|
263
|
+
result[key] = resultItem
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return promises.length == 0 ? result : promiseAll(promises).then(always(result))
|
|
267
|
+
}
|
|
215
268
|
|
|
216
|
-
const
|
|
269
|
+
const all = function (...args) {
|
|
270
|
+
const funcs = args.pop()
|
|
271
|
+
if (args.length == 0) {
|
|
272
|
+
return isArray(funcs)
|
|
273
|
+
? curryArgs2(functionArrayAll, funcs, __)
|
|
274
|
+
: curryArgs2(functionObjectAll, funcs, __)
|
|
275
|
+
}
|
|
217
276
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return isPromise(result)
|
|
223
|
-
? result.then(curry3(objectAssign, {}, value, __))
|
|
224
|
-
: ({ ...value, ...result })
|
|
277
|
+
if (areAnyValuesPromises(args)) {
|
|
278
|
+
return isArray(funcs)
|
|
279
|
+
? promiseAll(args).then(curry2(functionArrayAll, funcs, __))
|
|
280
|
+
: promiseAll(args).then(curry2(functionObjectAll, funcs, __))
|
|
225
281
|
}
|
|
226
|
-
}
|
|
227
282
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
283
|
+
return isArray(funcs)
|
|
284
|
+
? functionArrayAll(funcs, args)
|
|
285
|
+
: functionObjectAll(funcs, args)
|
|
231
286
|
}
|
|
232
287
|
|
|
233
|
-
|
|
234
|
-
|
|
288
|
+
all.series = function allSeries(...args) {
|
|
289
|
+
const funcs = args.pop()
|
|
290
|
+
if (args.length == 0) {
|
|
291
|
+
return curryArgs2(functionArrayAllSeries, funcs, __)
|
|
292
|
+
}
|
|
293
|
+
if (areAnyValuesPromises(args)) {
|
|
294
|
+
return promiseAll(args).then(curry2(functionArrayAllSeries, funcs, __))
|
|
295
|
+
}
|
|
296
|
+
return functionArrayAllSeries(funcs, args)
|
|
235
297
|
}
|
|
236
298
|
|
|
237
|
-
const
|
|
238
|
-
conditionalExpression, thunkOnTruthy, thunkOnFalsy,
|
|
239
|
-
) => conditionalExpression ? thunkOnTruthy() : thunkOnFalsy()
|
|
299
|
+
const objectAssign = Object.assign
|
|
240
300
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return isPromise(
|
|
301
|
+
// _assign(object Object, funcs Object<function>) -> Promise|Object
|
|
302
|
+
const _assign = function (object, funcs) {
|
|
303
|
+
const result = functionObjectAll(funcs, [object])
|
|
304
|
+
return isPromise(result)
|
|
305
|
+
? result.then(curry3(objectAssign, {}, object, __))
|
|
306
|
+
: ({ ...object, ...result })
|
|
245
307
|
}
|
|
246
308
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const predication = predicate(...args)
|
|
251
|
-
if (isPromise(predication)) {
|
|
252
|
-
return predication.then(curry3(
|
|
253
|
-
thunkConditional, __, thunkifyArgs(tap(func), args), always(args[0])))
|
|
254
|
-
}
|
|
255
|
-
if (predication) {
|
|
256
|
-
const execution = func(...args)
|
|
257
|
-
if (isPromise(execution)) {
|
|
258
|
-
return execution.then(always(args[0]))
|
|
259
|
-
}
|
|
309
|
+
const assign = function (arg0, arg1) {
|
|
310
|
+
if (arg1 == null) {
|
|
311
|
+
return curry2(_assign, __, arg0)
|
|
260
312
|
}
|
|
261
|
-
return
|
|
313
|
+
return isPromise(arg0)
|
|
314
|
+
? arg0.then(curry2(_assign, __, arg1))
|
|
315
|
+
: _assign(arg0, arg1)
|
|
262
316
|
}
|
|
263
317
|
|
|
264
318
|
const catcherApply = function (catcher, err, args) {
|
|
265
319
|
return catcher(err, ...args)
|
|
266
320
|
}
|
|
267
321
|
|
|
322
|
+
// _tryCatch(tryer function, catcher function, args Array) -> Promise
|
|
323
|
+
const _tryCatch = function (tryer, catcher, args) {
|
|
324
|
+
try {
|
|
325
|
+
const result = tryer(...args)
|
|
326
|
+
return isPromise(result)
|
|
327
|
+
? result.catch(curry3(catcherApply, catcher, __, args))
|
|
328
|
+
: result
|
|
329
|
+
} catch (error) {
|
|
330
|
+
return catcher(error, ...args)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
268
334
|
const tryCatch = function (...args) {
|
|
269
335
|
if (args.length > 2) {
|
|
270
336
|
const catcher = args.pop(),
|
|
271
337
|
tryer = args.pop()
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
? result.catch(curry3(catcherApply, catcher, __, args))
|
|
276
|
-
: result
|
|
277
|
-
} catch (error) {
|
|
278
|
-
return catcher(error, ...args)
|
|
338
|
+
if (areAnyValuesPromises(args)) {
|
|
339
|
+
return promiseAll(args)
|
|
340
|
+
.then(curry3(_tryCatch, tryer, catcher, __))
|
|
279
341
|
}
|
|
342
|
+
return _tryCatch(tryer, catcher, args)
|
|
280
343
|
}
|
|
281
344
|
|
|
282
345
|
const tryer = args[0],
|
|
283
346
|
catcher = args[1]
|
|
284
347
|
return function tryCatcher(...args) {
|
|
285
|
-
|
|
286
|
-
const result = tryer(...args)
|
|
287
|
-
return isPromise(result)
|
|
288
|
-
? result.catch(curry3(catcherApply, catcher, __, args))
|
|
289
|
-
: result
|
|
290
|
-
} catch (error) {
|
|
291
|
-
return catcher(error, ...args)
|
|
292
|
-
}
|
|
348
|
+
return _tryCatch(tryer, catcher, args)
|
|
293
349
|
}
|
|
294
350
|
}
|
|
295
351
|
|
|
@@ -377,13 +433,49 @@ const nonfunctionsConditional = function (array, index) {
|
|
|
377
433
|
return array[index]
|
|
378
434
|
}
|
|
379
435
|
|
|
380
|
-
|
|
436
|
+
// argument resolver for curryArgs3
|
|
437
|
+
const curryArgs3ResolveArgs0 = (
|
|
438
|
+
baseFunc, arg1, arg2,
|
|
439
|
+
) => function args0Resolver(...args) {
|
|
440
|
+
return baseFunc(args, arg1, arg2)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// argument resolver for curryArgs3
|
|
444
|
+
const curryArgs3ResolveArgs1 = (
|
|
445
|
+
baseFunc, arg0, arg2,
|
|
446
|
+
) => function arg1Resolver(...args) {
|
|
447
|
+
return baseFunc(arg0, args, arg2)
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// argument resolver for curryArgs3
|
|
451
|
+
const curryArgs3ResolveArgs2 = (
|
|
452
|
+
baseFunc, arg0, arg1,
|
|
453
|
+
) => function arg2Resolver(...args) {
|
|
454
|
+
return baseFunc(arg0, arg1, args)
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const curryArgs3 = function (baseFunc, arg0, arg1, arg2) {
|
|
458
|
+
if (arg0 == __) {
|
|
459
|
+
return curryArgs3ResolveArgs0(baseFunc, arg1, arg2)
|
|
460
|
+
}
|
|
461
|
+
if (arg1 == __) {
|
|
462
|
+
return curryArgs3ResolveArgs1(baseFunc, arg0, arg2)
|
|
463
|
+
}
|
|
464
|
+
return curryArgs3ResolveArgs2(baseFunc, arg0, arg1)
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const switchCase = (...args) => {
|
|
468
|
+
const values = args.pop()
|
|
381
469
|
if (areAllValuesNonfunctions(values)) {
|
|
382
470
|
return nonfunctionsConditional(values, -2)
|
|
383
471
|
}
|
|
384
|
-
|
|
385
|
-
return arrayConditional
|
|
472
|
+
if (args.length == 0) {
|
|
473
|
+
return curryArgs3(arrayConditional, values, __, -2)
|
|
386
474
|
}
|
|
475
|
+
if (areAnyValuesPromises(args)) {
|
|
476
|
+
return promiseAll(args).then(curry3(arrayConditional, values, __, -2))
|
|
477
|
+
}
|
|
478
|
+
return arrayConditional(values, args, -2)
|
|
387
479
|
}
|
|
388
480
|
|
|
389
481
|
const symbolIterator = Symbol.iterator
|
|
@@ -422,26 +514,6 @@ const MappingAsyncIterator = (asyncIterator, mapper) => ({
|
|
|
422
514
|
}
|
|
423
515
|
})
|
|
424
516
|
|
|
425
|
-
// argument resolver for curry2
|
|
426
|
-
const curry2ResolveArg0 = (
|
|
427
|
-
baseFunc, arg1,
|
|
428
|
-
) => function arg0Resolver(arg0) {
|
|
429
|
-
return baseFunc(arg0, arg1)
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
// argument resolver for curry2
|
|
433
|
-
const curry2ResolveArg1 = (
|
|
434
|
-
baseFunc, arg0,
|
|
435
|
-
) => function arg1Resolver(arg1) {
|
|
436
|
-
return baseFunc(arg0, arg1)
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
const curry2 = function (baseFunc, arg0, arg1) {
|
|
440
|
-
return arg0 == __
|
|
441
|
-
? curry2ResolveArg0(baseFunc, arg1)
|
|
442
|
-
: curry2ResolveArg1(baseFunc, arg0)
|
|
443
|
-
}
|
|
444
|
-
|
|
445
517
|
const isObject = value => {
|
|
446
518
|
if (value == null) {
|
|
447
519
|
return false
|
|
@@ -467,31 +539,6 @@ const arrayMap = function (array, mapper) {
|
|
|
467
539
|
return isAsync ? promiseAll(result) : result
|
|
468
540
|
}
|
|
469
541
|
|
|
470
|
-
const generatorFunctionMap = (
|
|
471
|
-
generatorFunc, mapper,
|
|
472
|
-
) => function* mappingGeneratorFunc(...args) {
|
|
473
|
-
for (const item of generatorFunc(...args)) {
|
|
474
|
-
yield mapper(item)
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
const asyncGeneratorFunctionMap = function (asyncGeneratorFunc, mapper) {
|
|
479
|
-
return async function* mappingAsyncGeneratorFunc(...args) {
|
|
480
|
-
for await (const item of asyncGeneratorFunc(...args)) {
|
|
481
|
-
yield mapper(item)
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
const reducerMap = (
|
|
487
|
-
reducer, mapper,
|
|
488
|
-
) => function mappingReducer(result, reducerItem) {
|
|
489
|
-
const mappingReducerItem = mapper(reducerItem)
|
|
490
|
-
return isPromise(mappingReducerItem)
|
|
491
|
-
? mappingReducerItem.then(curry2(reducer, result, __))
|
|
492
|
-
: reducer(result, mappingReducerItem)
|
|
493
|
-
}
|
|
494
|
-
|
|
495
542
|
const callPropUnary = (value, property, arg0) => value[property](arg0)
|
|
496
543
|
|
|
497
544
|
const stringMap = function (string, mapper) {
|
|
@@ -602,6 +649,11 @@ const arrayMapSeries = function (array, mapper) {
|
|
|
602
649
|
return result
|
|
603
650
|
}
|
|
604
651
|
|
|
652
|
+
const tapSync = func => function tapping(...args) {
|
|
653
|
+
func(...args)
|
|
654
|
+
return args[0]
|
|
655
|
+
}
|
|
656
|
+
|
|
605
657
|
const promiseRace = Promise.race.bind(Promise)
|
|
606
658
|
|
|
607
659
|
const arrayMapPoolAsync = async function (
|
|
@@ -647,38 +699,6 @@ const arrayMapPool = function (array, mapper, concurrentLimit) {
|
|
|
647
699
|
return result
|
|
648
700
|
}
|
|
649
701
|
|
|
650
|
-
const arrayMapWithIndex = function (array, mapper) {
|
|
651
|
-
const arrayLength = array.length,
|
|
652
|
-
result = Array(arrayLength)
|
|
653
|
-
let index = -1, isAsync = false
|
|
654
|
-
while (++index < arrayLength) {
|
|
655
|
-
const resultItem = mapper(array[index], index, array)
|
|
656
|
-
if (isPromise(resultItem)) {
|
|
657
|
-
isAsync = true
|
|
658
|
-
}
|
|
659
|
-
result[index] = resultItem
|
|
660
|
-
}
|
|
661
|
-
return isAsync ? promiseAll(result) : result
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty
|
|
665
|
-
const hasOwn = (obj, key) => hasOwnProperty.call(obj, key)
|
|
666
|
-
|
|
667
|
-
const objectMapOwn = function (object, mapper) {
|
|
668
|
-
const result = {}
|
|
669
|
-
let isAsync = false
|
|
670
|
-
for (const key in object) {
|
|
671
|
-
if (hasOwn(object, key)) {
|
|
672
|
-
const resultItem = mapper(object[key])
|
|
673
|
-
if (isPromise(resultItem)) {
|
|
674
|
-
isAsync = true
|
|
675
|
-
}
|
|
676
|
-
result[key] = resultItem
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
return isAsync ? promiseObjectAll(result) : result
|
|
680
|
-
}
|
|
681
|
-
|
|
682
702
|
const _curryArity = (arity, func, args) => function curried(...curriedArgs) {
|
|
683
703
|
const argsLength = args.length,
|
|
684
704
|
curriedArgsLength = curriedArgs.length,
|
|
@@ -786,15 +806,6 @@ const _map = function (value, mapper) {
|
|
|
786
806
|
if (isArray(value)) {
|
|
787
807
|
return arrayMap(value, mapper)
|
|
788
808
|
}
|
|
789
|
-
if (typeof value == 'function') {
|
|
790
|
-
if (isGeneratorFunction(value)) {
|
|
791
|
-
return generatorFunctionMap(value, mapper)
|
|
792
|
-
}
|
|
793
|
-
if (isAsyncGeneratorFunction(value)) {
|
|
794
|
-
return asyncGeneratorFunctionMap(value, mapper)
|
|
795
|
-
}
|
|
796
|
-
return reducerMap(value, mapper)
|
|
797
|
-
}
|
|
798
809
|
if (value == null) {
|
|
799
810
|
return value
|
|
800
811
|
}
|
|
@@ -828,10 +839,15 @@ const _map = function (value, mapper) {
|
|
|
828
839
|
|
|
829
840
|
const map = (...args) => {
|
|
830
841
|
const mapper = args.pop()
|
|
831
|
-
if (args.length
|
|
832
|
-
return _map
|
|
842
|
+
if (args.length == 0) {
|
|
843
|
+
return curry2(_map, __, mapper)
|
|
833
844
|
}
|
|
834
|
-
|
|
845
|
+
|
|
846
|
+
const collection = args[0]
|
|
847
|
+
if (isPromise(collection)) {
|
|
848
|
+
return collection.then(curry2(_map, __, mapper))
|
|
849
|
+
}
|
|
850
|
+
return _map(collection, mapper)
|
|
835
851
|
}
|
|
836
852
|
|
|
837
853
|
map.entries = function mapEntries(mapper) {
|
|
@@ -863,20 +879,6 @@ map.pool = (concurrencyLimit, mapper) => function concurrentPoolMapping(value) {
|
|
|
863
879
|
throw new TypeError(`${value} is not an Array`)
|
|
864
880
|
}
|
|
865
881
|
|
|
866
|
-
map.withIndex = mapper => function mappingWithIndex(value) {
|
|
867
|
-
if (isArray(value)) {
|
|
868
|
-
return arrayMapWithIndex(value, mapper)
|
|
869
|
-
}
|
|
870
|
-
throw new TypeError(`${value} is not an Array`)
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
map.own = mapper => function mappingOwnProperties(value) {
|
|
874
|
-
if (isObject(value) && !isArray(value)) {
|
|
875
|
-
return objectMapOwn(value, mapper)
|
|
876
|
-
}
|
|
877
|
-
throw new TypeError(`${value} is not an Object`)
|
|
878
|
-
}
|
|
879
|
-
|
|
880
882
|
const FilteringIterator = (iterator, predicate) => ({
|
|
881
883
|
[symbolIterator]() {
|
|
882
884
|
return this
|
|
@@ -946,12 +948,11 @@ const arrayFilter = function (array, predicate) {
|
|
|
946
948
|
resultIndex = -1
|
|
947
949
|
while (++index < arrayLength) {
|
|
948
950
|
const item = array[index],
|
|
949
|
-
shouldIncludeItem = predicate(item)
|
|
951
|
+
shouldIncludeItem = predicate(item, index, array)
|
|
950
952
|
if (isPromise(shouldIncludeItem)) {
|
|
951
953
|
return promiseAll(
|
|
952
|
-
arrayExtendMap(
|
|
953
|
-
|
|
954
|
-
curry4(arrayFilterByConditions, array, result, index - 1, __))
|
|
954
|
+
arrayExtendMap([shouldIncludeItem], array, predicate, index)
|
|
955
|
+
).then(curry4(arrayFilterByConditions, array, result, index - 1, __))
|
|
955
956
|
}
|
|
956
957
|
if (shouldIncludeItem) {
|
|
957
958
|
result[++resultIndex] = item
|
|
@@ -960,31 +961,6 @@ const arrayFilter = function (array, predicate) {
|
|
|
960
961
|
return result
|
|
961
962
|
}
|
|
962
963
|
|
|
963
|
-
const generatorFunctionFilter = (
|
|
964
|
-
generatorFunction, predicate,
|
|
965
|
-
) => function* filteringGeneratorFunction(...args) {
|
|
966
|
-
yield* FilteringIterator(generatorFunction(...args), predicate)
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
const asyncGeneratorFunctionFilter = (
|
|
970
|
-
asyncGeneratorFunction, predicate,
|
|
971
|
-
) => async function* filteringAsyncGeneratorFunction(...args) {
|
|
972
|
-
yield* FilteringAsyncIterator(asyncGeneratorFunction(...args), predicate)
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
const reducerFilter = (
|
|
976
|
-
reducer, predicate,
|
|
977
|
-
) => function filteringReducer(result, item) {
|
|
978
|
-
const shouldInclude = predicate(item)
|
|
979
|
-
return isPromise(shouldInclude)
|
|
980
|
-
? shouldInclude.then(curry3(
|
|
981
|
-
thunkConditional,
|
|
982
|
-
__,
|
|
983
|
-
thunkify2(reducer, result, item),
|
|
984
|
-
always(result)))
|
|
985
|
-
: shouldInclude ? reducer(result, item) : result
|
|
986
|
-
}
|
|
987
|
-
|
|
988
964
|
const stringFilter = function (string, predicate) {
|
|
989
965
|
const filteredCharactersArray = arrayFilter(string, predicate)
|
|
990
966
|
return isPromise(filteredCharactersArray)
|
|
@@ -996,6 +972,8 @@ const thunkify1 = (func, arg0) => function thunk() {
|
|
|
996
972
|
return func(arg0)
|
|
997
973
|
}
|
|
998
974
|
|
|
975
|
+
const noop = function () {}
|
|
976
|
+
|
|
999
977
|
const setFilter = function (value, predicate) {
|
|
1000
978
|
const result = new Set(),
|
|
1001
979
|
resultAdd = result.add.bind(result),
|
|
@@ -1062,53 +1040,10 @@ const objectFilter = function (object, predicate) {
|
|
|
1062
1040
|
: promiseAll(promises).then(always(result))
|
|
1063
1041
|
}
|
|
1064
1042
|
|
|
1065
|
-
const arrayExtendMapWithIndex = function (
|
|
1066
|
-
array, values, valuesMapper, valuesIndex,
|
|
1067
|
-
) {
|
|
1068
|
-
const valuesLength = values.length
|
|
1069
|
-
let arrayIndex = array.length - 1
|
|
1070
|
-
|
|
1071
|
-
while (++valuesIndex < valuesLength) {
|
|
1072
|
-
array[++arrayIndex] = valuesMapper(
|
|
1073
|
-
values[valuesIndex], valuesIndex, values)
|
|
1074
|
-
}
|
|
1075
|
-
return array
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
const arrayFilterWithIndex = function (array, predicate) {
|
|
1079
|
-
const arrayLength = array.length,
|
|
1080
|
-
result = []
|
|
1081
|
-
let index = -1,
|
|
1082
|
-
resultIndex = -1
|
|
1083
|
-
while (++index < arrayLength) {
|
|
1084
|
-
const item = array[index],
|
|
1085
|
-
shouldIncludeItem = predicate(item, index, array)
|
|
1086
|
-
if (isPromise(shouldIncludeItem)) {
|
|
1087
|
-
return promiseAll(
|
|
1088
|
-
arrayExtendMapWithIndex(
|
|
1089
|
-
[shouldIncludeItem], array, predicate, index)).then(
|
|
1090
|
-
curry4(arrayFilterByConditions, array, result, index - 1, __))
|
|
1091
|
-
}
|
|
1092
|
-
if (shouldIncludeItem) {
|
|
1093
|
-
result[++resultIndex] = item
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
return result
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
1043
|
const _filter = function (value, predicate) {
|
|
1100
1044
|
if (isArray(value)) {
|
|
1101
1045
|
return arrayFilter(value, predicate)
|
|
1102
1046
|
}
|
|
1103
|
-
if (typeof value == 'function') {
|
|
1104
|
-
if (isGeneratorFunction(value)) {
|
|
1105
|
-
return generatorFunctionFilter(value, predicate)
|
|
1106
|
-
}
|
|
1107
|
-
if (isAsyncGeneratorFunction(value)) {
|
|
1108
|
-
return asyncGeneratorFunctionFilter(value, predicate)
|
|
1109
|
-
}
|
|
1110
|
-
return reducerFilter(value, predicate)
|
|
1111
|
-
}
|
|
1112
1047
|
if (value == null) {
|
|
1113
1048
|
return value
|
|
1114
1049
|
}
|
|
@@ -1139,51 +1074,27 @@ const _filter = function (value, predicate) {
|
|
|
1139
1074
|
|
|
1140
1075
|
const filter = function (...args) {
|
|
1141
1076
|
const predicate = args.pop()
|
|
1142
|
-
if (args.length
|
|
1143
|
-
return _filter
|
|
1077
|
+
if (args.length == 0) {
|
|
1078
|
+
return curry2(_filter, __, predicate)
|
|
1144
1079
|
}
|
|
1145
|
-
return
|
|
1080
|
+
return _filter(args[0], predicate)
|
|
1146
1081
|
}
|
|
1147
1082
|
|
|
1148
|
-
|
|
1149
|
-
if (isArray(value)) {
|
|
1150
|
-
return arrayFilterWithIndex(value, predicate)
|
|
1151
|
-
}
|
|
1152
|
-
throw new TypeError(`${value} is not an Array`)
|
|
1153
|
-
}
|
|
1083
|
+
const objectValues = Object.values
|
|
1154
1084
|
|
|
1155
|
-
|
|
1156
|
-
const curryArgs3ResolveArgs0 = (
|
|
1157
|
-
baseFunc, arg1, arg2,
|
|
1158
|
-
) => function args0Resolver(...args) {
|
|
1159
|
-
return baseFunc(args, arg1, arg2)
|
|
1160
|
-
}
|
|
1085
|
+
const objectProto = Object.prototype
|
|
1161
1086
|
|
|
1162
|
-
|
|
1163
|
-
const curryArgs3ResolveArgs1 = (
|
|
1164
|
-
baseFunc, arg0, arg2,
|
|
1165
|
-
) => function arg1Resolver(...args) {
|
|
1166
|
-
return baseFunc(arg0, args, arg2)
|
|
1167
|
-
}
|
|
1087
|
+
const nativeObjectToString = objectProto.toString
|
|
1168
1088
|
|
|
1169
|
-
|
|
1170
|
-
const curryArgs3ResolveArgs2 = (
|
|
1171
|
-
baseFunc, arg0, arg1,
|
|
1172
|
-
) => function arg2Resolver(...args) {
|
|
1173
|
-
return baseFunc(arg0, arg1, args)
|
|
1174
|
-
}
|
|
1089
|
+
const objectToString = value => nativeObjectToString.call(value)
|
|
1175
1090
|
|
|
1176
|
-
const
|
|
1177
|
-
if (arg0 == __) {
|
|
1178
|
-
return curryArgs3ResolveArgs0(baseFunc, arg1, arg2)
|
|
1179
|
-
}
|
|
1180
|
-
if (arg1 == __) {
|
|
1181
|
-
return curryArgs3ResolveArgs1(baseFunc, arg0, arg2)
|
|
1182
|
-
}
|
|
1183
|
-
return curryArgs3ResolveArgs2(baseFunc, arg0, arg1)
|
|
1184
|
-
}
|
|
1091
|
+
const generatorFunctionTag = '[object GeneratorFunction]'
|
|
1185
1092
|
|
|
1186
|
-
const
|
|
1093
|
+
const isGeneratorFunction = value => objectToString(value) == generatorFunctionTag
|
|
1094
|
+
|
|
1095
|
+
const asyncGeneratorFunctionTag = '[object AsyncGeneratorFunction]'
|
|
1096
|
+
|
|
1097
|
+
const isAsyncGeneratorFunction = value => objectToString(value) == asyncGeneratorFunctionTag
|
|
1187
1098
|
|
|
1188
1099
|
const iteratorReduceAsync = async function (
|
|
1189
1100
|
iterator, reducer, result,
|
|
@@ -1320,13 +1231,6 @@ const curry5 = function (baseFunc, arg0, arg1, arg2, arg3, arg4) {
|
|
|
1320
1231
|
|
|
1321
1232
|
const objectKeys = Object.keys
|
|
1322
1233
|
|
|
1323
|
-
const objectGetFirstKey = function (object) {
|
|
1324
|
-
for (const key in object) {
|
|
1325
|
-
return key
|
|
1326
|
-
}
|
|
1327
|
-
return undefined
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
1234
|
const objectReduceAsync = async function (object, reducer, result, keys, index) {
|
|
1331
1235
|
const keysLength = keys.length
|
|
1332
1236
|
while (++index < keysLength) {
|
|
@@ -1387,18 +1291,6 @@ const mapReduce = function (map, reducer, result) {
|
|
|
1387
1291
|
return result
|
|
1388
1292
|
}
|
|
1389
1293
|
|
|
1390
|
-
const generatorFunctionReduce = (
|
|
1391
|
-
generatorFunction, reducer, result,
|
|
1392
|
-
) => funcConcatSync(
|
|
1393
|
-
generatorFunction,
|
|
1394
|
-
curry3(iteratorReduce, __, reducer, result))
|
|
1395
|
-
|
|
1396
|
-
const asyncGeneratorFunctionReduce = (
|
|
1397
|
-
asyncGeneratorFunction, reducer, result,
|
|
1398
|
-
) => funcConcatSync(
|
|
1399
|
-
asyncGeneratorFunction,
|
|
1400
|
-
curry3(asyncIteratorReduce, __, reducer, result))
|
|
1401
|
-
|
|
1402
1294
|
const reducerConcat = (
|
|
1403
1295
|
reducerA, reducerB,
|
|
1404
1296
|
) => function pipedReducer(result, item) {
|
|
@@ -1408,26 +1300,10 @@ const reducerConcat = (
|
|
|
1408
1300
|
: reducerB(intermediate, item)
|
|
1409
1301
|
}
|
|
1410
1302
|
|
|
1411
|
-
const genericReduce = function (
|
|
1412
|
-
const collection = args[0]
|
|
1303
|
+
const genericReduce = function (collection, reducer, result) {
|
|
1413
1304
|
if (isArray(collection)) {
|
|
1414
1305
|
return arrayReduce(collection, reducer, result)
|
|
1415
1306
|
}
|
|
1416
|
-
if (typeof collection == 'function') {
|
|
1417
|
-
if (isGeneratorFunction(collection)) {
|
|
1418
|
-
return generatorFunctionReduce(collection, reducer, result)
|
|
1419
|
-
}
|
|
1420
|
-
if (isAsyncGeneratorFunction(collection)) {
|
|
1421
|
-
return asyncGeneratorFunctionReduce(collection, reducer, result)
|
|
1422
|
-
}
|
|
1423
|
-
return curryArgs3(
|
|
1424
|
-
genericReduce,
|
|
1425
|
-
__,
|
|
1426
|
-
args.length == 1
|
|
1427
|
-
? reducerConcat(reducer, collection)
|
|
1428
|
-
: args.reduce(reducerConcat, reducer),
|
|
1429
|
-
result)
|
|
1430
|
-
}
|
|
1431
1307
|
if (collection == null) {
|
|
1432
1308
|
return result === undefined
|
|
1433
1309
|
? curry2(reducer, collection, __)
|
|
@@ -1462,38 +1338,33 @@ const genericReduce = function (args, reducer, result) {
|
|
|
1462
1338
|
: reducer(result, collection)
|
|
1463
1339
|
}
|
|
1464
1340
|
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
const
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
return genericReduce([args[0]], reducer, initialValue)
|
|
1341
|
+
// _reduce(collection any, reducer function, initialValue function|any) -> Promise
|
|
1342
|
+
const _reduce = function (collection, reducer, initialValue) {
|
|
1343
|
+
if (typeof initialValue == 'function') {
|
|
1344
|
+
const actualInitialValue = initialValue(collection)
|
|
1345
|
+
return isPromise(actualInitialValue)
|
|
1346
|
+
? actualInitialValue.then(curry3(genericReduce, collection, reducer, __))
|
|
1347
|
+
: genericReduce(collection, reducer, actualInitialValue)
|
|
1473
1348
|
}
|
|
1349
|
+
return isPromise(initialValue)
|
|
1350
|
+
? initialValue.then(curry3(genericReduce, collection, reducer, __))
|
|
1351
|
+
: genericReduce(collection, reducer, initialValue)
|
|
1352
|
+
}
|
|
1474
1353
|
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
return isPromise(result)
|
|
1482
|
-
? result.then(curry3(genericReduce, args, reducer, __))
|
|
1483
|
-
: genericReduce(args, reducer, result)
|
|
1484
|
-
}
|
|
1354
|
+
const reduce = function (...args) {
|
|
1355
|
+
if (typeof args[0] == 'function') {
|
|
1356
|
+
return curry3(_reduce, __, args[0], args[1])
|
|
1357
|
+
}
|
|
1358
|
+
if (isPromise(args[0])) {
|
|
1359
|
+
return args[0].then(curry3(_reduce, __, args[1], args[2]))
|
|
1485
1360
|
}
|
|
1486
|
-
return
|
|
1361
|
+
return _reduce(args[0], args[1], args[2])
|
|
1487
1362
|
}
|
|
1488
1363
|
|
|
1489
1364
|
const isBinary = ArrayBuffer.isView
|
|
1490
1365
|
|
|
1491
1366
|
const add = (a, b) => a + b
|
|
1492
1367
|
|
|
1493
|
-
const isArrayLike = function (value) {
|
|
1494
|
-
return value != null && value.length > 0
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
1368
|
const _arrayExtend = function (array, values) {
|
|
1498
1369
|
const arrayLength = array.length,
|
|
1499
1370
|
valuesLength = values.length
|
|
@@ -1505,7 +1376,7 @@ const _arrayExtend = function (array, values) {
|
|
|
1505
1376
|
}
|
|
1506
1377
|
|
|
1507
1378
|
const arrayExtend = function (array, values) {
|
|
1508
|
-
if (
|
|
1379
|
+
if (isArray(values) || isBinary(values)) {
|
|
1509
1380
|
return _arrayExtend(array, values)
|
|
1510
1381
|
}
|
|
1511
1382
|
array.push(values)
|
|
@@ -1576,57 +1447,66 @@ const callConcat = function (object, values) {
|
|
|
1576
1447
|
return object.concat(values)
|
|
1577
1448
|
}
|
|
1578
1449
|
|
|
1579
|
-
const identityTransform = function (
|
|
1580
|
-
const nil = genericReduce(
|
|
1450
|
+
const identityTransform = function (collection, transducer, result) {
|
|
1451
|
+
const nil = genericReduce(collection, transducer(noop), null)
|
|
1581
1452
|
return isPromise(nil) ? nil.then(always(result)) : result
|
|
1582
1453
|
}
|
|
1583
1454
|
|
|
1584
|
-
const genericTransform = function (
|
|
1455
|
+
const genericTransform = function (collection, transducer, result) {
|
|
1585
1456
|
if (isArray(result)) {
|
|
1586
|
-
return genericReduce(
|
|
1457
|
+
return genericReduce(collection, transducer(arrayExtend), result)
|
|
1587
1458
|
}
|
|
1588
1459
|
if (isBinary(result)) {
|
|
1589
|
-
const intermediateArray = genericReduce(
|
|
1460
|
+
const intermediateArray = genericReduce(collection, transducer(arrayExtend), [])
|
|
1590
1461
|
return isPromise(intermediateArray)
|
|
1591
1462
|
? intermediateArray.then(curry2(binaryExtend, result, __))
|
|
1592
1463
|
: binaryExtend(result, intermediateArray)
|
|
1593
1464
|
}
|
|
1594
1465
|
if (result == null) {
|
|
1595
|
-
return identityTransform(
|
|
1466
|
+
return identityTransform(collection, transducer, result)
|
|
1596
1467
|
}
|
|
1597
1468
|
|
|
1598
1469
|
const resultConstructor = result.constructor
|
|
1599
1470
|
if (typeof result == 'string' || resultConstructor == String) {
|
|
1600
1471
|
// TODO: use array + join over adding
|
|
1601
|
-
return genericReduce(
|
|
1472
|
+
return genericReduce(collection, transducer(add), result)
|
|
1602
1473
|
}
|
|
1603
1474
|
if (typeof result.concat == 'function') {
|
|
1604
|
-
return genericReduce(
|
|
1475
|
+
return genericReduce(collection, transducer(callConcat), result)
|
|
1605
1476
|
}
|
|
1606
1477
|
if (typeof result.write == 'function') {
|
|
1607
|
-
return genericReduce(
|
|
1478
|
+
return genericReduce(collection, transducer(streamExtend), result)
|
|
1608
1479
|
}
|
|
1609
1480
|
if (resultConstructor == Set) {
|
|
1610
|
-
return genericReduce(
|
|
1481
|
+
return genericReduce(collection, transducer(setExtend), result)
|
|
1611
1482
|
}
|
|
1612
1483
|
if (resultConstructor == Object) {
|
|
1613
|
-
return genericReduce(
|
|
1484
|
+
return genericReduce(collection, transducer(objectAssign), result)
|
|
1614
1485
|
}
|
|
1615
|
-
return identityTransform(
|
|
1486
|
+
return identityTransform(collection, transducer, result)
|
|
1616
1487
|
}
|
|
1617
1488
|
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1489
|
+
// _transform(collection any, transducer function, initialValue function|any) -> Promise
|
|
1490
|
+
const _transform = function (collection, transducer, initialValue) {
|
|
1491
|
+
if (typeof initialValue == 'function') {
|
|
1492
|
+
const actualInitialValue = initialValue(collection)
|
|
1493
|
+
return isPromise(actualInitialValue)
|
|
1494
|
+
? actualInitialValue.then(curry3(genericTransform, collection, transducer, __))
|
|
1495
|
+
: genericTransform(collection, transducer, actualInitialValue)
|
|
1496
|
+
}
|
|
1497
|
+
return isPromise(initialValue)
|
|
1498
|
+
? initialValue.then(curry3(genericTransform, collection, transducer, __))
|
|
1499
|
+
: genericTransform(collection, transducer, initialValue)
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
const transform = function (...args) {
|
|
1503
|
+
if (typeof args[0] == 'function') {
|
|
1504
|
+
return curry3(_transform, __, args[0], args[1])
|
|
1626
1505
|
}
|
|
1627
|
-
|
|
1628
|
-
return
|
|
1506
|
+
if (isPromise(args[0])) {
|
|
1507
|
+
return args[0].then(curry3(_transform, __, args[1], args[2]))
|
|
1629
1508
|
}
|
|
1509
|
+
return _transform(args[0], args[1], args[2])
|
|
1630
1510
|
}
|
|
1631
1511
|
|
|
1632
1512
|
const arrayPush = function (array, value) {
|
|
@@ -1653,7 +1533,7 @@ const FlatMappingIterator = function (iterator, flatMapper) {
|
|
|
1653
1533
|
return iteration
|
|
1654
1534
|
}
|
|
1655
1535
|
const monadAsArray = genericReduce(
|
|
1656
|
-
|
|
1536
|
+
flatMapper(iteration.value),
|
|
1657
1537
|
arrayPush,
|
|
1658
1538
|
[]) // this will always have at least one item
|
|
1659
1539
|
if (monadAsArray.length > 1) {
|
|
@@ -1697,12 +1577,12 @@ const FlatMappingAsyncIterator = function (asyncIterator, flatMapper) {
|
|
|
1697
1577
|
} else {
|
|
1698
1578
|
const monad = flatMapper(value)
|
|
1699
1579
|
if (isPromise(monad)) {
|
|
1700
|
-
const bufferLoading =
|
|
1701
|
-
|
|
1580
|
+
const bufferLoading =
|
|
1581
|
+
monad.then(curry3(genericReduce, __, arrayPush, buffer))
|
|
1702
1582
|
const promise = bufferLoading.then(() => promises.delete(promise))
|
|
1703
1583
|
promises.add(promise)
|
|
1704
1584
|
} else {
|
|
1705
|
-
const bufferLoading = genericReduce(
|
|
1585
|
+
const bufferLoading = genericReduce(monad, arrayPush, buffer)
|
|
1706
1586
|
if (isPromise(bufferLoading)) {
|
|
1707
1587
|
const promise = bufferLoading.then(() => promises.delete(promise))
|
|
1708
1588
|
promises.add(promise)
|
|
@@ -1726,6 +1606,12 @@ const getArg1 = (arg0, arg1) => arg1
|
|
|
1726
1606
|
|
|
1727
1607
|
const identity = value => value
|
|
1728
1608
|
|
|
1609
|
+
const funcConcatSync = (
|
|
1610
|
+
funcA, funcB,
|
|
1611
|
+
) => function pipedFunction(...args) {
|
|
1612
|
+
return funcB(funcA(...args))
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1729
1615
|
const asyncIteratorForEach = async function (asyncIterator, callback) {
|
|
1730
1616
|
const promises = []
|
|
1731
1617
|
for await (const item of asyncIterator) {
|
|
@@ -1912,177 +1798,120 @@ const stringFlatMap = function (string, flatMapper) {
|
|
|
1912
1798
|
: arrayFlattenToString(monadArray)
|
|
1913
1799
|
}
|
|
1914
1800
|
|
|
1915
|
-
const
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
|
-
const streamFlatExtend = async function (stream, item) {
|
|
1921
|
-
const resultStreamWrite = curry2(streamWrite, stream, __),
|
|
1922
|
-
// resultStreamWriteReducer = (_, subItem) => stream.write(subItem),
|
|
1923
|
-
resultStreamWriteReducer = funcConcatSync(getArg1, resultStreamWrite),
|
|
1924
|
-
promises = []
|
|
1925
|
-
if (isArray(item)) {
|
|
1926
|
-
const itemLength = item.length
|
|
1927
|
-
let itemIndex = -1
|
|
1928
|
-
while (++itemIndex < itemLength) {
|
|
1929
|
-
stream.write(item[itemIndex])
|
|
1930
|
-
}
|
|
1931
|
-
} else if (item == null) {
|
|
1932
|
-
stream.write(item)
|
|
1933
|
-
} else if (typeof item[symbolIterator] == 'function') {
|
|
1934
|
-
for (const subItem of item) {
|
|
1935
|
-
stream.write(subItem)
|
|
1936
|
-
}
|
|
1937
|
-
} else if (typeof item[symbolAsyncIterator] == 'function') {
|
|
1938
|
-
promises.push(
|
|
1939
|
-
asyncIteratorForEach(item[symbolAsyncIterator](), resultStreamWrite))
|
|
1940
|
-
} else if (typeof item.chain == 'function') {
|
|
1941
|
-
const monadValue = item.chain(identity)
|
|
1942
|
-
isPromise(monadValue)
|
|
1943
|
-
? promises.push(monadValue.then(resultStreamWrite))
|
|
1944
|
-
: stream.write(monadValue)
|
|
1945
|
-
} else if (typeof item.flatMap == 'function') {
|
|
1946
|
-
const monadValue = item.flatMap(identity)
|
|
1947
|
-
isPromise(monadValue)
|
|
1948
|
-
? promises.push(monadValue.then(resultStreamWrite))
|
|
1949
|
-
: stream.write(monadValue)
|
|
1950
|
-
} else if (typeof item.reduce == 'function') {
|
|
1951
|
-
const folded = item.reduce(resultStreamWriteReducer, null)
|
|
1952
|
-
isPromise(folded) && promises.push(folded)
|
|
1953
|
-
} else if (item.constructor == Object) {
|
|
1954
|
-
for (const key in item) {
|
|
1955
|
-
stream.write(item[key])
|
|
1956
|
-
}
|
|
1957
|
-
} else {
|
|
1958
|
-
stream.write(item)
|
|
1801
|
+
const _flatMap = function (value, flatMapper) {
|
|
1802
|
+
if (isArray(value)) {
|
|
1803
|
+
return arrayFlatMap(value, flatMapper)
|
|
1959
1804
|
}
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
: promiseAll(promises).then(always(stream))
|
|
1963
|
-
}
|
|
1964
|
-
|
|
1965
|
-
const streamFlatMap = async function (stream, flatMapper) {
|
|
1966
|
-
const promises = new Set()
|
|
1967
|
-
for await (const item of stream) {
|
|
1968
|
-
const monad = flatMapper(item)
|
|
1969
|
-
if (isPromise(monad)) {
|
|
1970
|
-
const selfDeletingPromise = monad.then(
|
|
1971
|
-
curry2(streamFlatExtend, stream, __)).then(
|
|
1972
|
-
() => promises.delete(selfDeletingPromise))
|
|
1973
|
-
promises.add(selfDeletingPromise)
|
|
1974
|
-
} else {
|
|
1975
|
-
const streamFlatteningOperation = streamFlatExtend(stream, monad)
|
|
1976
|
-
if (isPromise(streamFlatteningOperation)) {
|
|
1977
|
-
const selfDeletingPromise = streamFlatteningOperation.then(
|
|
1978
|
-
() => promises.delete(selfDeletingPromise))
|
|
1979
|
-
promises.add(selfDeletingPromise)
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
1805
|
+
if (value == null) {
|
|
1806
|
+
return flatMapper(value)
|
|
1982
1807
|
}
|
|
1983
|
-
await promiseAll(promises)
|
|
1984
|
-
return stream
|
|
1985
|
-
}
|
|
1986
1808
|
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
let index = -1,
|
|
1990
|
-
result = init
|
|
1991
|
-
while (++index < length) {
|
|
1992
|
-
result = binaryExtend(result, array[index])
|
|
1809
|
+
if (typeof value.then == 'function') {
|
|
1810
|
+
return value.then(flatMapper)
|
|
1993
1811
|
}
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
const
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
1812
|
+
if (typeof value.next == 'function') {
|
|
1813
|
+
return symbolIterator in value
|
|
1814
|
+
? FlatMappingIterator(value, flatMapper)
|
|
1815
|
+
: FlatMappingAsyncIterator(value, flatMapper)
|
|
1816
|
+
}
|
|
1817
|
+
if (typeof value.chain == 'function') {
|
|
1818
|
+
return value.chain(flatMapper)
|
|
1819
|
+
}
|
|
1820
|
+
if (typeof value.flatMap == 'function') {
|
|
1821
|
+
return value.flatMap(flatMapper)
|
|
1822
|
+
}
|
|
1823
|
+
const valueConstructor = value.constructor
|
|
1824
|
+
if (valueConstructor == Object) {
|
|
1825
|
+
return objectFlatMap(value, flatMapper)
|
|
1826
|
+
}
|
|
1827
|
+
if (valueConstructor == Set) {
|
|
1828
|
+
return setFlatMap(value, flatMapper)
|
|
1829
|
+
}
|
|
1830
|
+
if (typeof value == 'string' || valueConstructor == String) {
|
|
1831
|
+
return stringFlatMap(value, flatMapper)
|
|
1832
|
+
}
|
|
1833
|
+
return flatMapper(value)
|
|
2012
1834
|
}
|
|
2013
1835
|
|
|
2014
|
-
const
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
1836
|
+
const flatMap = (...args) => {
|
|
1837
|
+
const flatMapper = args.pop()
|
|
1838
|
+
if (args.length == 0) {
|
|
1839
|
+
return curry2(_flatMap, __, flatMapper)
|
|
1840
|
+
}
|
|
1841
|
+
const collection = args[0]
|
|
1842
|
+
return isPromise(collection)
|
|
1843
|
+
? collection.then(curry2(_flatMap, __, flatMapper))
|
|
1844
|
+
: _flatMap(args[0], flatMapper)
|
|
2021
1845
|
}
|
|
2022
1846
|
|
|
2023
|
-
const
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
1847
|
+
const arrayForEach = function (array, callback) {
|
|
1848
|
+
const length = array.length,
|
|
1849
|
+
promises = []
|
|
1850
|
+
let index = -1
|
|
1851
|
+
while (++index < length) {
|
|
1852
|
+
const operation = callback(array[index])
|
|
1853
|
+
if (isPromise(operation)) {
|
|
1854
|
+
promises.push(operation)
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
return promises.length == 0 ? array : promiseAll(promises).then(always(array))
|
|
2027
1858
|
}
|
|
2028
1859
|
|
|
2029
|
-
const
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
1860
|
+
const objectForEach = function (object, callback) {
|
|
1861
|
+
const promises = []
|
|
1862
|
+
for (const key in object) {
|
|
1863
|
+
const operation = callback(object[key])
|
|
1864
|
+
if (isPromise(operation)) {
|
|
1865
|
+
promises.push(operation)
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
return promises.length == 0 ? object : promiseAll(promises).then(always(object))
|
|
2033
1869
|
}
|
|
2034
1870
|
|
|
2035
|
-
const
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
return generatorFunctionFlatMap(value, flatMapper)
|
|
2042
|
-
}
|
|
2043
|
-
if (isAsyncGeneratorFunction(value)) {
|
|
2044
|
-
return asyncGeneratorFunctionFlatMap(value, flatMapper)
|
|
1871
|
+
const iteratorForEach = function (iterator, callback) {
|
|
1872
|
+
const promises = []
|
|
1873
|
+
for (const item of iterator) {
|
|
1874
|
+
const operation = callback(item)
|
|
1875
|
+
if (isPromise(operation)) {
|
|
1876
|
+
promises.push(operation)
|
|
2045
1877
|
}
|
|
2046
|
-
return reducerFlatMap(value, flatMapper)
|
|
2047
|
-
}
|
|
2048
|
-
if (isBinary(value)) {
|
|
2049
|
-
return binaryFlatMap(value, flatMapper)
|
|
2050
|
-
}
|
|
2051
|
-
if (value == null) {
|
|
2052
|
-
return flatMapper(value)
|
|
2053
1878
|
}
|
|
1879
|
+
return promises.length == 0 ? iterator : promiseAll(promises).then(always(iterator))
|
|
1880
|
+
}
|
|
2054
1881
|
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
if (
|
|
2059
|
-
return
|
|
2060
|
-
? FlatMappingIterator(value, flatMapper)
|
|
2061
|
-
: FlatMappingAsyncIterator(value, flatMapper)
|
|
1882
|
+
// type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
|
|
1883
|
+
// _forEach(collection Collection, callback function) -> collection Collection
|
|
1884
|
+
const _forEach = function (collection, callback) {
|
|
1885
|
+
if (isArray(collection)) {
|
|
1886
|
+
return arrayForEach(collection, callback)
|
|
2062
1887
|
}
|
|
2063
|
-
if (
|
|
2064
|
-
return
|
|
1888
|
+
if (collection == null) {
|
|
1889
|
+
return collection
|
|
2065
1890
|
}
|
|
2066
|
-
if (typeof
|
|
2067
|
-
return
|
|
1891
|
+
if (typeof collection.forEach == 'function') {
|
|
1892
|
+
return collection.forEach(callback)
|
|
2068
1893
|
}
|
|
2069
|
-
if (
|
|
2070
|
-
|
|
2071
|
-
&& typeof value.write == 'function'
|
|
2072
|
-
) {
|
|
2073
|
-
return streamFlatMap(value, flatMapper)
|
|
1894
|
+
if (typeof collection[symbolIterator] == 'function') {
|
|
1895
|
+
return iteratorForEach(collection[symbolIterator](), callback)
|
|
2074
1896
|
}
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
return objectFlatMap(value, flatMapper)
|
|
1897
|
+
if (typeof collection[symbolAsyncIterator] == 'function') {
|
|
1898
|
+
return asyncIteratorForEach(collection[symbolAsyncIterator](), callback)
|
|
2078
1899
|
}
|
|
2079
|
-
if (
|
|
2080
|
-
return
|
|
1900
|
+
if (collection.constructor == Object) {
|
|
1901
|
+
return objectForEach(collection, callback)
|
|
2081
1902
|
}
|
|
2082
|
-
|
|
2083
|
-
|
|
1903
|
+
return collection
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
const forEach = function (...args) {
|
|
1907
|
+
const callback = args.pop()
|
|
1908
|
+
if (args.length == 0) {
|
|
1909
|
+
return curry2(_forEach, __, callback)
|
|
2084
1910
|
}
|
|
2085
|
-
|
|
1911
|
+
const collection = args[0]
|
|
1912
|
+
return isPromise(collection)
|
|
1913
|
+
? collection.then(curry2(_forEach, __, callback))
|
|
1914
|
+
: _forEach(collection, callback)
|
|
2086
1915
|
}
|
|
2087
1916
|
|
|
2088
1917
|
const SelfReferencingPromise = function (basePromise) {
|
|
@@ -2090,7 +1919,7 @@ const SelfReferencingPromise = function (basePromise) {
|
|
|
2090
1919
|
return promise
|
|
2091
1920
|
}
|
|
2092
1921
|
|
|
2093
|
-
const
|
|
1922
|
+
const asyncArraySome = async function (
|
|
2094
1923
|
array, predicate, index, promisesInFlight,
|
|
2095
1924
|
) {
|
|
2096
1925
|
const length = array.length
|
|
@@ -2113,13 +1942,13 @@ const asyncArrayAny = async function (
|
|
|
2113
1942
|
return false
|
|
2114
1943
|
}
|
|
2115
1944
|
|
|
2116
|
-
const
|
|
1945
|
+
const arraySome = function (array, predicate) {
|
|
2117
1946
|
const length = array.length
|
|
2118
1947
|
let index = -1
|
|
2119
1948
|
while (++index < length) {
|
|
2120
1949
|
const predication = predicate(array[index])
|
|
2121
1950
|
if (isPromise(predication)) {
|
|
2122
|
-
return
|
|
1951
|
+
return asyncArraySome(
|
|
2123
1952
|
array, predicate, index, new Set([SelfReferencingPromise(predication)]))
|
|
2124
1953
|
}
|
|
2125
1954
|
if (predication) {
|
|
@@ -2129,7 +1958,7 @@ const arrayAny = function (array, predicate) {
|
|
|
2129
1958
|
return false
|
|
2130
1959
|
}
|
|
2131
1960
|
|
|
2132
|
-
const
|
|
1961
|
+
const asyncIteratorSome = async function (
|
|
2133
1962
|
iterator, predicate, promisesInFlight, maxConcurrency = 20,
|
|
2134
1963
|
) {
|
|
2135
1964
|
let iteration = iterator.next()
|
|
@@ -2166,11 +1995,11 @@ const asyncIteratorAny = async function (
|
|
|
2166
1995
|
return false
|
|
2167
1996
|
}
|
|
2168
1997
|
|
|
2169
|
-
const
|
|
1998
|
+
const iteratorSome = function (iterator, predicate) {
|
|
2170
1999
|
for (const item of iterator) {
|
|
2171
2000
|
const predication = predicate(item)
|
|
2172
2001
|
if (isPromise(predication)) {
|
|
2173
|
-
return
|
|
2002
|
+
return asyncIteratorSome(
|
|
2174
2003
|
iterator, predicate, new Set([SelfReferencingPromise(predication)]))
|
|
2175
2004
|
}
|
|
2176
2005
|
if (predication) {
|
|
@@ -2184,35 +2013,52 @@ const reducerAnySync = predicate => function anyReducer(result, item) {
|
|
|
2184
2013
|
return result ? true : predicate(item)
|
|
2185
2014
|
}
|
|
2186
2015
|
|
|
2187
|
-
const
|
|
2016
|
+
const reducerSome = predicate => function anyReducer(result, item) {
|
|
2188
2017
|
return result === true ? result
|
|
2189
2018
|
: isPromise(result) ? result.then(curry2(reducerAnySync(predicate), __, item))
|
|
2190
2019
|
: result ? true : predicate(item)
|
|
2191
2020
|
}
|
|
2192
2021
|
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2022
|
+
// _some(collection Array|Iterable|AsyncIterable|{ reduce: function }|Object, predicate function) -> Promise|boolean
|
|
2023
|
+
const _some = function (collection, predicate) {
|
|
2024
|
+
if (isArray(collection)) {
|
|
2025
|
+
return arraySome(collection, predicate)
|
|
2196
2026
|
}
|
|
2197
|
-
if (
|
|
2198
|
-
return predicate(
|
|
2027
|
+
if (collection == null) {
|
|
2028
|
+
return predicate(collection)
|
|
2199
2029
|
}
|
|
2200
|
-
if (typeof
|
|
2201
|
-
return
|
|
2030
|
+
if (typeof collection[symbolIterator] == 'function') {
|
|
2031
|
+
return iteratorSome(collection[symbolIterator](), predicate)
|
|
2202
2032
|
}
|
|
2203
|
-
if (typeof
|
|
2204
|
-
return
|
|
2033
|
+
if (typeof collection[symbolAsyncIterator] == 'function') {
|
|
2034
|
+
return asyncIteratorSome(
|
|
2035
|
+
collection[symbolAsyncIterator](), predicate, new Set()
|
|
2036
|
+
)
|
|
2205
2037
|
}
|
|
2206
|
-
if (typeof
|
|
2207
|
-
return
|
|
2038
|
+
if (typeof collection.reduce == 'function') {
|
|
2039
|
+
return collection.reduce(reducerSome(predicate), false)
|
|
2208
2040
|
}
|
|
2209
|
-
if (
|
|
2210
|
-
return
|
|
2041
|
+
if (collection.constructor == Object) {
|
|
2042
|
+
return arraySome(objectValues(collection), predicate)
|
|
2043
|
+
}
|
|
2044
|
+
return predicate(collection)
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
const some = function (...args) {
|
|
2048
|
+
const predicate = args.pop()
|
|
2049
|
+
if (args.length == 0) {
|
|
2050
|
+
return curry2(_some, __, predicate)
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
const collection = args[0]
|
|
2054
|
+
if (isPromise(collection)) {
|
|
2055
|
+
return collection.then(curry2(_some, __, predicate))
|
|
2211
2056
|
}
|
|
2212
|
-
|
|
2057
|
+
|
|
2058
|
+
return _some(collection, predicate)
|
|
2213
2059
|
}
|
|
2214
2060
|
|
|
2215
|
-
const
|
|
2061
|
+
const arrayEvery = function (array, predicate) {
|
|
2216
2062
|
const arrayLength = array.length,
|
|
2217
2063
|
promises = []
|
|
2218
2064
|
let index = -1
|
|
@@ -2229,7 +2075,7 @@ const arrayAll = function (array, predicate) {
|
|
|
2229
2075
|
: promiseAll(promises).then(curry3(callPropUnary, __, 'every', Boolean))
|
|
2230
2076
|
}
|
|
2231
2077
|
|
|
2232
|
-
const
|
|
2078
|
+
const iteratorEvery = function (iterator, predicate) {
|
|
2233
2079
|
const promises = []
|
|
2234
2080
|
for (const item of iterator) {
|
|
2235
2081
|
const predication = predicate(item)
|
|
@@ -2244,7 +2090,7 @@ const iteratorAll = function (iterator, predicate) {
|
|
|
2244
2090
|
: promiseAll(promises).then(curry3(callPropUnary, __, 'every', Boolean))
|
|
2245
2091
|
}
|
|
2246
2092
|
|
|
2247
|
-
const
|
|
2093
|
+
const asyncIteratorEvery = async function (
|
|
2248
2094
|
asyncIterator, predicate, promisesInFlight, maxConcurrency = 20,
|
|
2249
2095
|
) {
|
|
2250
2096
|
let iteration = await asyncIterator.next()
|
|
@@ -2277,45 +2123,62 @@ const asyncIteratorAll = async function (
|
|
|
2277
2123
|
|
|
2278
2124
|
const reducerAllSync = (predicate, result, item) => result ? predicate(item) : false
|
|
2279
2125
|
|
|
2280
|
-
const
|
|
2126
|
+
const reducerEvery = predicate => function allReducer(result, item) {
|
|
2281
2127
|
return result === false ? false
|
|
2282
2128
|
: isPromise(result) ? result.then(
|
|
2283
2129
|
curry3(reducerAllSync, predicate, __, item))
|
|
2284
2130
|
: result ? predicate(item) : false
|
|
2285
2131
|
}
|
|
2286
2132
|
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2133
|
+
// _every(collection Array|Iterable|AsyncIterable|{ reduce: function }|Object, predicate function) -> Promise|boolean
|
|
2134
|
+
const _every = function (collection, predicate) {
|
|
2135
|
+
if (isArray(collection)) {
|
|
2136
|
+
return arrayEvery(collection, predicate)
|
|
2290
2137
|
}
|
|
2291
|
-
if (
|
|
2292
|
-
return predicate(
|
|
2138
|
+
if (collection == null) {
|
|
2139
|
+
return predicate(collection)
|
|
2293
2140
|
}
|
|
2294
2141
|
|
|
2295
|
-
if (typeof
|
|
2296
|
-
return
|
|
2142
|
+
if (typeof collection[symbolIterator] == 'function') {
|
|
2143
|
+
return iteratorEvery(collection[symbolIterator](), predicate)
|
|
2297
2144
|
}
|
|
2298
|
-
if (typeof
|
|
2299
|
-
return
|
|
2145
|
+
if (typeof collection[symbolAsyncIterator] == 'function') {
|
|
2146
|
+
return asyncIteratorEvery(
|
|
2147
|
+
collection[symbolAsyncIterator](), predicate, new Set()
|
|
2148
|
+
)
|
|
2300
2149
|
}
|
|
2301
|
-
if (typeof
|
|
2302
|
-
return
|
|
2150
|
+
if (typeof collection.reduce == 'function') {
|
|
2151
|
+
return collection.reduce(reducerEvery(predicate), true)
|
|
2303
2152
|
}
|
|
2304
|
-
if (
|
|
2305
|
-
return
|
|
2153
|
+
if (collection.constructor == Object) {
|
|
2154
|
+
return arrayEvery(objectValues(collection), predicate)
|
|
2306
2155
|
}
|
|
2307
|
-
return predicate(
|
|
2156
|
+
return predicate(collection)
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
const every = function (...args) {
|
|
2160
|
+
const predicate = args.pop()
|
|
2161
|
+
if (args.length == 0) {
|
|
2162
|
+
return curry2(_every, __, predicate)
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
const collection = args[0]
|
|
2166
|
+
if (isPromise(collection)) {
|
|
2167
|
+
return collection.then(curry2(_every, __, predicate))
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
return _every(collection, predicate)
|
|
2308
2171
|
}
|
|
2309
2172
|
|
|
2310
|
-
const
|
|
2173
|
+
const areAllValuesTruthy = function (predicates, index) {
|
|
2311
2174
|
const length = predicates.length
|
|
2312
2175
|
while (++index < length) {
|
|
2313
|
-
|
|
2176
|
+
const predicate = predicates[index]
|
|
2314
2177
|
if (isPromise(predicate)) {
|
|
2315
2178
|
return predicate.then(curry3(
|
|
2316
2179
|
thunkConditional,
|
|
2317
2180
|
__,
|
|
2318
|
-
thunkify2(
|
|
2181
|
+
thunkify2(areAllValuesTruthy, predicates, index),
|
|
2319
2182
|
always(false),
|
|
2320
2183
|
))
|
|
2321
2184
|
}
|
|
@@ -2326,12 +2189,12 @@ const areAllNonfunctionsTruthy = function (predicates, index) {
|
|
|
2326
2189
|
return true
|
|
2327
2190
|
}
|
|
2328
2191
|
|
|
2329
|
-
const asyncArePredicatesAllTruthy = async function (
|
|
2192
|
+
const asyncArePredicatesAllTruthy = async function (args, predicates, index) {
|
|
2330
2193
|
const length = predicates.length
|
|
2331
2194
|
while (++index < length) {
|
|
2332
2195
|
let predicate = predicates[index]
|
|
2333
2196
|
if (typeof predicate == 'function') {
|
|
2334
|
-
predicate = predicate(
|
|
2197
|
+
predicate = predicate(...args)
|
|
2335
2198
|
}
|
|
2336
2199
|
if (isPromise(predicate)) {
|
|
2337
2200
|
predicate = await predicate
|
|
@@ -2343,39 +2206,53 @@ const asyncArePredicatesAllTruthy = async function (predicates, point, index) {
|
|
|
2343
2206
|
return true
|
|
2344
2207
|
}
|
|
2345
2208
|
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
return function arePredicatesAllTruthy(point) {
|
|
2351
|
-
const length = predicates.length
|
|
2352
|
-
let index = -1
|
|
2209
|
+
// areAllPredicatesTruthy(args Array, predicates Array<function>) -> Promise|boolean
|
|
2210
|
+
const areAllPredicatesTruthy = function (args, predicates) {
|
|
2211
|
+
const length = predicates.length
|
|
2212
|
+
let index = -1
|
|
2353
2213
|
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
}
|
|
2214
|
+
while (++index < length) {
|
|
2215
|
+
let predicate = predicates[index]
|
|
2216
|
+
if (typeof predicate == 'function') {
|
|
2217
|
+
predicate = predicate(...args)
|
|
2218
|
+
}
|
|
2219
|
+
if (isPromise(predicate)) {
|
|
2220
|
+
return predicate.then(curry3(
|
|
2221
|
+
thunkConditional,
|
|
2222
|
+
__,
|
|
2223
|
+
thunkify3(asyncArePredicatesAllTruthy, args, predicates, index),
|
|
2224
|
+
always(false),
|
|
2225
|
+
))
|
|
2226
|
+
}
|
|
2227
|
+
if (!predicate) {
|
|
2228
|
+
return false
|
|
2370
2229
|
}
|
|
2371
|
-
return true
|
|
2372
2230
|
}
|
|
2231
|
+
return true
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
const and = function (...args) {
|
|
2235
|
+
const predicatesOrValues = args.pop()
|
|
2236
|
+
if (areAllValuesNonfunctions(predicatesOrValues)) {
|
|
2237
|
+
return areAllValuesTruthy(predicatesOrValues, -1)
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
if (args.length == 0) {
|
|
2241
|
+
return curryArgs2(areAllPredicatesTruthy, __, predicatesOrValues)
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
if (areAnyValuesPromises(args)) {
|
|
2245
|
+
return promiseAll(args)
|
|
2246
|
+
.then(curry2(areAllPredicatesTruthy, __, predicatesOrValues))
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
return areAllPredicatesTruthy(args, predicatesOrValues)
|
|
2373
2250
|
}
|
|
2374
2251
|
|
|
2375
2252
|
const areAnyNonfunctionsTruthy = function (predicates, index) {
|
|
2376
2253
|
const length = predicates.length
|
|
2377
2254
|
while (++index < length) {
|
|
2378
|
-
|
|
2255
|
+
const predicate = predicates[index]
|
|
2379
2256
|
if (isPromise(predicate)) {
|
|
2380
2257
|
return predicate.then(curry3(
|
|
2381
2258
|
thunkConditional,
|
|
@@ -2391,14 +2268,13 @@ const areAnyNonfunctionsTruthy = function (predicates, index) {
|
|
|
2391
2268
|
return false
|
|
2392
2269
|
}
|
|
2393
2270
|
|
|
2394
|
-
const asyncAreAnyPredicatesTruthy = async function (
|
|
2271
|
+
const asyncAreAnyPredicatesTruthy = async function (args, predicates, index) {
|
|
2395
2272
|
const length = predicates.length
|
|
2396
2273
|
while (++index < length) {
|
|
2397
2274
|
let predicate = predicates[index]
|
|
2398
2275
|
if (typeof predicate == 'function') {
|
|
2399
|
-
predicate = predicate(
|
|
2276
|
+
predicate = predicate(...args)
|
|
2400
2277
|
}
|
|
2401
|
-
console.log('hey - or', predicate)
|
|
2402
2278
|
if (isPromise(predicate)) {
|
|
2403
2279
|
predicate = await predicate
|
|
2404
2280
|
}
|
|
@@ -2409,275 +2285,225 @@ const asyncAreAnyPredicatesTruthy = async function (predicates, point, index) {
|
|
|
2409
2285
|
return false
|
|
2410
2286
|
}
|
|
2411
2287
|
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
return function areAnyPredicatesTruthy(point) {
|
|
2417
|
-
const length = predicates.length
|
|
2418
|
-
let index = -1
|
|
2288
|
+
// areAnyPredicatesTruthy(args Array, predicates Array<function>) -> Promise|boolean
|
|
2289
|
+
const areAnyPredicatesTruthy = function (args, predicates) {
|
|
2290
|
+
const length = predicates.length
|
|
2291
|
+
let index = -1
|
|
2419
2292
|
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
}
|
|
2293
|
+
while (++index < length) {
|
|
2294
|
+
let predicate = predicates[index]
|
|
2295
|
+
if (typeof predicate == 'function') {
|
|
2296
|
+
predicate = predicate(...args)
|
|
2297
|
+
}
|
|
2298
|
+
if (isPromise(predicate)) {
|
|
2299
|
+
return predicate.then(curry3(
|
|
2300
|
+
thunkConditional,
|
|
2301
|
+
__,
|
|
2302
|
+
always(true),
|
|
2303
|
+
thunkify3(asyncAreAnyPredicatesTruthy, args, predicates, index),
|
|
2304
|
+
))
|
|
2305
|
+
}
|
|
2306
|
+
if (predicate) {
|
|
2307
|
+
return true
|
|
2436
2308
|
}
|
|
2437
|
-
return false
|
|
2438
2309
|
}
|
|
2310
|
+
return false
|
|
2439
2311
|
}
|
|
2440
2312
|
|
|
2441
|
-
|
|
2442
|
-
const
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
if (typeof funcOrValue == 'function') {
|
|
2446
|
-
return function logicalInverter(value) {
|
|
2447
|
-
const boolean = funcOrValue(value)
|
|
2448
|
-
return isPromise(boolean) ? boolean.then(_not) : !boolean
|
|
2449
|
-
}
|
|
2313
|
+
const or = function (...args) {
|
|
2314
|
+
const predicatesOrValues = args.pop()
|
|
2315
|
+
if (areAllValuesNonfunctions(predicatesOrValues)) {
|
|
2316
|
+
return areAnyNonfunctionsTruthy(predicatesOrValues, -1)
|
|
2450
2317
|
}
|
|
2451
|
-
return !funcOrValue
|
|
2452
|
-
}
|
|
2453
2318
|
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
}
|
|
2319
|
+
if (args.length == 0) {
|
|
2320
|
+
return curryArgs2(areAnyPredicatesTruthy, __, predicatesOrValues)
|
|
2321
|
+
}
|
|
2457
2322
|
|
|
2458
|
-
|
|
2323
|
+
if (areAnyValuesPromises(args)) {
|
|
2324
|
+
return promiseAll(args)
|
|
2325
|
+
.then(curry2(areAnyPredicatesTruthy, __, predicatesOrValues))
|
|
2326
|
+
}
|
|
2459
2327
|
|
|
2460
|
-
|
|
2461
|
-
return left === right || (left !== left && right !== right)
|
|
2328
|
+
return areAnyPredicatesTruthy(args, predicatesOrValues)
|
|
2462
2329
|
}
|
|
2463
2330
|
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
isRightResolver = typeof right == 'function'
|
|
2331
|
+
// negate(value boolean) -> inverse boolean
|
|
2332
|
+
const negate = value => !value
|
|
2467
2333
|
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
isRightPromise = isPromise(rightResolve)
|
|
2474
|
-
if (isLeftPromise && isRightPromise) {
|
|
2475
|
-
return promiseAll(
|
|
2476
|
-
[leftResolve, rightResolve]).then(spread2(sameValueZero))
|
|
2477
|
-
} else if (isLeftPromise) {
|
|
2478
|
-
return leftResolve.then(curry2(sameValueZero, __, rightResolve))
|
|
2479
|
-
} else if (isRightPromise) {
|
|
2480
|
-
return rightResolve.then(curry2(sameValueZero, leftResolve, __))
|
|
2481
|
-
}
|
|
2482
|
-
return sameValueZero(leftResolve, rightResolve)
|
|
2483
|
-
}
|
|
2484
|
-
}
|
|
2334
|
+
// _not(args Array, predicate function)
|
|
2335
|
+
const _not = function (args, predicate) {
|
|
2336
|
+
const boolean = predicate(...args)
|
|
2337
|
+
return isPromise(boolean) ? boolean.then(negate) : !boolean
|
|
2338
|
+
}
|
|
2485
2339
|
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
: sameValueZero(leftResolve, right)
|
|
2340
|
+
const not = function (...args) {
|
|
2341
|
+
const predicateOrValue = args.pop()
|
|
2342
|
+
if (typeof predicateOrValue == 'function') {
|
|
2343
|
+
if (args.length == 0) {
|
|
2344
|
+
return curryArgs2(_not, __, predicateOrValue)
|
|
2492
2345
|
}
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
return function equalBy(value) {
|
|
2496
|
-
const rightResolve = right(value)
|
|
2497
|
-
return isPromise(rightResolve)
|
|
2498
|
-
? rightResolve.then(curry2(sameValueZero, left, __))
|
|
2499
|
-
: sameValueZero(left, rightResolve)
|
|
2346
|
+
if (areAnyValuesPromises(args)) {
|
|
2347
|
+
return promiseAll(args).then(curry2(_not, __, predicateOrValue))
|
|
2500
2348
|
}
|
|
2349
|
+
return _not(args, predicateOrValue)
|
|
2501
2350
|
}
|
|
2351
|
+
return !predicateOrValue
|
|
2352
|
+
}
|
|
2502
2353
|
|
|
2503
|
-
|
|
2354
|
+
// argument resolver for curryArgs4
|
|
2355
|
+
const curryArgs4ResolveArgs0 = (
|
|
2356
|
+
baseFunc, arg1, arg2, arg3,
|
|
2357
|
+
) => function args0Resolver(...args) {
|
|
2358
|
+
return baseFunc(args, arg1, arg2, arg3)
|
|
2504
2359
|
}
|
|
2505
2360
|
|
|
2506
|
-
|
|
2361
|
+
// argument resolver for curryArgs4
|
|
2362
|
+
const curryArgs4ResolveArgs1 = (
|
|
2363
|
+
baseFunc, arg0, arg2, arg3,
|
|
2364
|
+
) => function args1Resolver(...args) {
|
|
2365
|
+
return baseFunc(arg0, args, arg2, arg3)
|
|
2366
|
+
}
|
|
2507
2367
|
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2368
|
+
// argument resolver for curryArgs4
|
|
2369
|
+
const curryArgs4ResolveArgs2 = (
|
|
2370
|
+
baseFunc, arg0, arg1, arg3,
|
|
2371
|
+
) => function args2Resolver(...args) {
|
|
2372
|
+
return baseFunc(arg0, arg1, args, arg3)
|
|
2373
|
+
}
|
|
2511
2374
|
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
if (isLeftPromise && isRightPromise) {
|
|
2519
|
-
return promiseAll(
|
|
2520
|
-
[leftResolve, rightResolve]).then(spread2(greaterThan))
|
|
2521
|
-
} else if (isLeftPromise) {
|
|
2522
|
-
return leftResolve.then(curry2(greaterThan, __, rightResolve))
|
|
2523
|
-
} else if (isRightPromise) {
|
|
2524
|
-
return rightResolve.then(curry2(greaterThan, leftResolve, __))
|
|
2525
|
-
}
|
|
2526
|
-
return leftResolve > rightResolve
|
|
2527
|
-
}
|
|
2528
|
-
}
|
|
2375
|
+
// argument resolver for curryArgs4
|
|
2376
|
+
const curryArgs4ResolveArgs3 = (
|
|
2377
|
+
baseFunc, arg0, arg1, arg2,
|
|
2378
|
+
) => function args3Resolver(...args) {
|
|
2379
|
+
return baseFunc(arg0, arg1, arg2, args)
|
|
2380
|
+
}
|
|
2529
2381
|
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
return isPromise(leftResolve)
|
|
2534
|
-
? leftResolve.then(curry2(greaterThan, __, right))
|
|
2535
|
-
: leftResolve > right
|
|
2536
|
-
}
|
|
2382
|
+
const curryArgs4 = function (baseFunc, arg0, arg1, arg2, arg3) {
|
|
2383
|
+
if (arg0 == __) {
|
|
2384
|
+
return curryArgs4ResolveArgs0(baseFunc, arg1, arg2, arg3)
|
|
2537
2385
|
}
|
|
2538
|
-
if (
|
|
2539
|
-
return
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2386
|
+
if (arg1 == __) {
|
|
2387
|
+
return curryArgs4ResolveArgs1(baseFunc, arg0, arg2, arg3)
|
|
2388
|
+
}
|
|
2389
|
+
if (arg2 == __) {
|
|
2390
|
+
return curryArgs4ResolveArgs2(baseFunc, arg0, arg1, arg3)
|
|
2391
|
+
}
|
|
2392
|
+
return curryArgs4ResolveArgs3(baseFunc, arg0, arg1, arg2)
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
// leftResolverRightResolverCompare(
|
|
2396
|
+
// args Array, comparator function, left function, right function,
|
|
2397
|
+
// ) -> Promise|boolean
|
|
2398
|
+
const leftResolverRightResolverCompare = function (
|
|
2399
|
+
args, comparator, left, right,
|
|
2400
|
+
) {
|
|
2401
|
+
const leftResult = left(...args),
|
|
2402
|
+
rightResult = right(...args)
|
|
2403
|
+
if (isPromise(leftResult) || isPromise(rightResult)) {
|
|
2404
|
+
return promiseAll([leftResult, rightResult]).then(spread2(comparator))
|
|
2545
2405
|
}
|
|
2406
|
+
return comparator(leftResult, rightResult)
|
|
2407
|
+
}
|
|
2546
2408
|
|
|
2547
|
-
|
|
2409
|
+
// leftResolverRightValueCompare(
|
|
2410
|
+
// args Array, comparator function, left function, right any
|
|
2411
|
+
// ) -> Promise|boolean
|
|
2412
|
+
const leftResolverRightValueCompare = function (args, comparator, left, right) {
|
|
2413
|
+
const leftResult = left(...args)
|
|
2414
|
+
if (isPromise(leftResult) || isPromise(right)) {
|
|
2415
|
+
return promiseAll([leftResult, right]).then(spread2(comparator))
|
|
2416
|
+
}
|
|
2417
|
+
return comparator(leftResult, right)
|
|
2548
2418
|
}
|
|
2549
2419
|
|
|
2550
|
-
|
|
2420
|
+
// leftValueRightResolverCompare(
|
|
2421
|
+
// args Array, comparator function, left any, right any,
|
|
2422
|
+
// ) -> Promise|boolean
|
|
2423
|
+
const leftValueRightResolverCompare = function (args, comparator, left, right) {
|
|
2424
|
+
const rightResult = right(...args)
|
|
2425
|
+
if (isPromise(left) || isPromise(rightResult)) {
|
|
2426
|
+
return promiseAll([left, rightResult]).then(spread2(comparator))
|
|
2427
|
+
}
|
|
2428
|
+
return comparator(left, rightResult)
|
|
2429
|
+
}
|
|
2551
2430
|
|
|
2552
|
-
|
|
2431
|
+
// ComparisonOperator(comparator function) -> operator function
|
|
2432
|
+
const ComparisonOperator = comparator => function operator(...args) {
|
|
2433
|
+
const right = args.pop()
|
|
2434
|
+
const left = args.pop()
|
|
2553
2435
|
const isLeftResolver = typeof left == 'function',
|
|
2554
2436
|
isRightResolver = typeof right == 'function'
|
|
2555
2437
|
|
|
2556
2438
|
if (isLeftResolver && isRightResolver) {
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
isRightPromise = isPromise(rightResolve)
|
|
2562
|
-
if (isLeftPromise && isRightPromise) {
|
|
2563
|
-
return promiseAll(
|
|
2564
|
-
[leftResolve, rightResolve]).then(spread2(lessThan))
|
|
2565
|
-
} else if (isLeftPromise) {
|
|
2566
|
-
return leftResolve.then(curry2(lessThan, __, rightResolve))
|
|
2567
|
-
} else if (isRightPromise) {
|
|
2568
|
-
return rightResolve.then(curry2(lessThan, leftResolve, __))
|
|
2569
|
-
}
|
|
2570
|
-
return leftResolve < rightResolve
|
|
2439
|
+
if (args.length == 0) {
|
|
2440
|
+
return curryArgs4(
|
|
2441
|
+
leftResolverRightResolverCompare, __, comparator, left, right,
|
|
2442
|
+
)
|
|
2571
2443
|
}
|
|
2444
|
+
if (areAnyValuesPromises(args)) {
|
|
2445
|
+
return promiseAll(args).then(curry4(
|
|
2446
|
+
leftResolverRightResolverCompare, __, comparator, left, right,
|
|
2447
|
+
))
|
|
2448
|
+
}
|
|
2449
|
+
return leftResolverRightResolverCompare(args, comparator, left, right)
|
|
2572
2450
|
}
|
|
2573
2451
|
|
|
2574
2452
|
if (isLeftResolver) {
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2453
|
+
if (args.length == 0) {
|
|
2454
|
+
return curryArgs4(
|
|
2455
|
+
leftResolverRightValueCompare, __, comparator, left, right,
|
|
2456
|
+
)
|
|
2457
|
+
}
|
|
2458
|
+
if (areAnyValuesPromises(args)) {
|
|
2459
|
+
return promiseAll(args).then(curry4(
|
|
2460
|
+
leftResolverRightValueCompare, __, comparator, left, right,
|
|
2461
|
+
))
|
|
2580
2462
|
}
|
|
2463
|
+
return leftResolverRightValueCompare(args, comparator, left, right)
|
|
2581
2464
|
}
|
|
2465
|
+
|
|
2582
2466
|
if (isRightResolver) {
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2467
|
+
if (args.length == 0) {
|
|
2468
|
+
return curryArgs4(
|
|
2469
|
+
leftValueRightResolverCompare, __, comparator, left, right,
|
|
2470
|
+
)
|
|
2471
|
+
}
|
|
2472
|
+
if (areAnyValuesPromises(args)) {
|
|
2473
|
+
return promiseAll(args).then(curry4(
|
|
2474
|
+
leftValueRightResolverCompare, __, comparator, left, right,
|
|
2475
|
+
))
|
|
2588
2476
|
}
|
|
2477
|
+
return leftValueRightResolverCompare(args, comparator, left, right)
|
|
2589
2478
|
}
|
|
2590
2479
|
|
|
2591
|
-
|
|
2480
|
+
if (isPromise(left) || isPromise(right)) {
|
|
2481
|
+
return promiseAll([left, right]).then(spread2(comparator))
|
|
2482
|
+
}
|
|
2483
|
+
return comparator(left, right)
|
|
2592
2484
|
}
|
|
2593
2485
|
|
|
2594
|
-
const
|
|
2486
|
+
const equals = function (left, right) {
|
|
2487
|
+
return left == right
|
|
2488
|
+
}
|
|
2595
2489
|
|
|
2596
|
-
const
|
|
2597
|
-
const isLeftResolver = typeof left == 'function',
|
|
2598
|
-
isRightResolver = typeof right == 'function'
|
|
2490
|
+
const eq = ComparisonOperator(equals)
|
|
2599
2491
|
|
|
2600
|
-
|
|
2601
|
-
return function greaterThanOrEqualBy(value) {
|
|
2602
|
-
const leftResolve = left(value),
|
|
2603
|
-
rightResolve = right(value)
|
|
2604
|
-
const isLeftPromise = isPromise(leftResolve),
|
|
2605
|
-
isRightPromise = isPromise(rightResolve)
|
|
2606
|
-
if (isLeftPromise && isRightPromise) {
|
|
2607
|
-
return promiseAll(
|
|
2608
|
-
[leftResolve, rightResolve]).then(spread2(greaterThanOrEqual))
|
|
2609
|
-
} else if (isLeftPromise) {
|
|
2610
|
-
return leftResolve.then(curry2(greaterThanOrEqual, __, rightResolve))
|
|
2611
|
-
} else if (isRightPromise) {
|
|
2612
|
-
return rightResolve.then(curry2(greaterThanOrEqual, leftResolve, __))
|
|
2613
|
-
}
|
|
2614
|
-
return leftResolve >= rightResolve
|
|
2615
|
-
}
|
|
2616
|
-
}
|
|
2492
|
+
const greaterThan = (left, right) => left > right
|
|
2617
2493
|
|
|
2618
|
-
|
|
2619
|
-
return function greaterThanOrEqualBy(value) {
|
|
2620
|
-
const leftResolve = left(value)
|
|
2621
|
-
return isPromise(leftResolve)
|
|
2622
|
-
? leftResolve.then(curry2(greaterThanOrEqual, __, right))
|
|
2623
|
-
: leftResolve >= right
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
if (isRightResolver) {
|
|
2627
|
-
return function greaterThanOrEqualBy(value) {
|
|
2628
|
-
const rightResolve = right(value)
|
|
2629
|
-
return isPromise(rightResolve)
|
|
2630
|
-
? rightResolve.then(curry2(greaterThanOrEqual, left, __))
|
|
2631
|
-
: left >= rightResolve
|
|
2632
|
-
}
|
|
2633
|
-
}
|
|
2494
|
+
const gt = ComparisonOperator(greaterThan)
|
|
2634
2495
|
|
|
2635
|
-
|
|
2636
|
-
}
|
|
2496
|
+
const lessThan = (left, right) => left < right
|
|
2637
2497
|
|
|
2638
|
-
const
|
|
2498
|
+
const lt = ComparisonOperator(lessThan)
|
|
2639
2499
|
|
|
2640
|
-
const
|
|
2641
|
-
const isLeftResolver = typeof left == 'function',
|
|
2642
|
-
isRightResolver = typeof right == 'function'
|
|
2500
|
+
const greaterThanOrEqual = (left, right) => left >= right
|
|
2643
2501
|
|
|
2644
|
-
|
|
2645
|
-
return function lessThanOrEqualBy(value) {
|
|
2646
|
-
const leftResolve = left(value),
|
|
2647
|
-
rightResolve = right(value)
|
|
2648
|
-
const isLeftPromise = isPromise(leftResolve),
|
|
2649
|
-
isRightPromise = isPromise(rightResolve)
|
|
2650
|
-
if (isLeftPromise && isRightPromise) {
|
|
2651
|
-
return promiseAll(
|
|
2652
|
-
[leftResolve, rightResolve]).then(spread2(lessThanOrEqual))
|
|
2653
|
-
} else if (isLeftPromise) {
|
|
2654
|
-
return leftResolve.then(curry2(lessThanOrEqual, __, rightResolve))
|
|
2655
|
-
} else if (isRightPromise) {
|
|
2656
|
-
return rightResolve.then(curry2(lessThanOrEqual, leftResolve, __))
|
|
2657
|
-
}
|
|
2658
|
-
return leftResolve <= rightResolve
|
|
2659
|
-
}
|
|
2660
|
-
}
|
|
2502
|
+
const gte = ComparisonOperator(greaterThanOrEqual)
|
|
2661
2503
|
|
|
2662
|
-
|
|
2663
|
-
return function lessThanOrEqualBy(value) {
|
|
2664
|
-
const leftResolve = left(value)
|
|
2665
|
-
return isPromise(leftResolve)
|
|
2666
|
-
? leftResolve.then(curry2(lessThanOrEqual, __, right))
|
|
2667
|
-
: leftResolve <= right
|
|
2668
|
-
}
|
|
2669
|
-
}
|
|
2670
|
-
if (isRightResolver) {
|
|
2671
|
-
return function lessThanOrEqualBy(value) {
|
|
2672
|
-
const rightResolve = right(value)
|
|
2673
|
-
return isPromise(rightResolve)
|
|
2674
|
-
? rightResolve.then(curry2(lessThanOrEqual, left, __))
|
|
2675
|
-
: left <= rightResolve
|
|
2676
|
-
}
|
|
2677
|
-
}
|
|
2504
|
+
const lessThanOrEqual = (left, right) => left <= right
|
|
2678
2505
|
|
|
2679
|
-
|
|
2680
|
-
}
|
|
2506
|
+
const lte = ComparisonOperator(lessThanOrEqual)
|
|
2681
2507
|
|
|
2682
2508
|
const memoizeCappedUnary = function (func, cap) {
|
|
2683
2509
|
const cache = new Map(),
|
|
@@ -2737,13 +2563,24 @@ const getByPath = function (value, path) {
|
|
|
2737
2563
|
return result
|
|
2738
2564
|
}
|
|
2739
2565
|
|
|
2740
|
-
|
|
2741
|
-
|
|
2566
|
+
// _get(object Object, path string, defaultValue function|any)
|
|
2567
|
+
const _get = function (object, path, defaultValue) {
|
|
2568
|
+
const result = object == null ? undefined : getByPath(object, path)
|
|
2742
2569
|
return result === undefined
|
|
2743
|
-
? typeof defaultValue == 'function' ? defaultValue(
|
|
2570
|
+
? typeof defaultValue == 'function' ? defaultValue(object) : defaultValue
|
|
2744
2571
|
: result
|
|
2745
2572
|
}
|
|
2746
2573
|
|
|
2574
|
+
const get = function (arg0, arg1, arg2) {
|
|
2575
|
+
if (isPromise(arg0)) {
|
|
2576
|
+
return arg0.then(curry3(_get, __, arg1, arg2))
|
|
2577
|
+
}
|
|
2578
|
+
if (isObject(arg0) && !isArray(arg0)) {
|
|
2579
|
+
return _get(arg0, arg1, arg2)
|
|
2580
|
+
}
|
|
2581
|
+
return curry3(_get, __, arg0, arg1)
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2747
2584
|
const setByPath = function (obj, value, path) {
|
|
2748
2585
|
if (!isObject(obj)){
|
|
2749
2586
|
return obj
|
|
@@ -2769,7 +2606,7 @@ const setByPath = function (obj, value, path) {
|
|
|
2769
2606
|
return result
|
|
2770
2607
|
}
|
|
2771
2608
|
|
|
2772
|
-
const
|
|
2609
|
+
const _set = function (obj, path, value) {
|
|
2773
2610
|
if (typeof value == 'function') {
|
|
2774
2611
|
const actualValue = value(obj)
|
|
2775
2612
|
if (isPromise(actualValue)) {
|
|
@@ -2779,9 +2616,24 @@ const set = (path, value) => function setter(obj) {
|
|
|
2779
2616
|
}
|
|
2780
2617
|
return setByPath(obj, actualValue, path)
|
|
2781
2618
|
}
|
|
2619
|
+
if (isPromise(value)) {
|
|
2620
|
+
return value.then(
|
|
2621
|
+
curry3(setByPath, obj, __, path)
|
|
2622
|
+
)
|
|
2623
|
+
}
|
|
2782
2624
|
return setByPath(obj, value, path)
|
|
2783
2625
|
}
|
|
2784
2626
|
|
|
2627
|
+
const set = function (arg0, arg1, arg2) {
|
|
2628
|
+
if (arg2 == null) {
|
|
2629
|
+
return curry3(_set, __, arg0, arg1)
|
|
2630
|
+
}
|
|
2631
|
+
if (isPromise(arg0)) {
|
|
2632
|
+
return arg0.then(curry3(_set, __, arg1, arg2))
|
|
2633
|
+
}
|
|
2634
|
+
return _set(arg0, arg1, arg2)
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2785
2637
|
// _pick(source Object, keys Array<string>) -> result Object
|
|
2786
2638
|
const _pick = function (source, keys) {
|
|
2787
2639
|
if (source == null) {
|
|
@@ -2800,10 +2652,13 @@ const _pick = function (source, keys) {
|
|
|
2800
2652
|
return result
|
|
2801
2653
|
}
|
|
2802
2654
|
|
|
2803
|
-
const pick = (arg0, arg1)
|
|
2655
|
+
const pick = function (arg0, arg1) {
|
|
2804
2656
|
if (arg1 == null) {
|
|
2805
2657
|
return curry2(_pick, __, arg0)
|
|
2806
2658
|
}
|
|
2659
|
+
if (isPromise(arg0)) {
|
|
2660
|
+
return arg0.then(curry2(_pick, __, arg1))
|
|
2661
|
+
}
|
|
2807
2662
|
return _pick(arg0, arg1)
|
|
2808
2663
|
}
|
|
2809
2664
|
|
|
@@ -2890,10 +2745,16 @@ const omit = function (arg0, arg1) {
|
|
|
2890
2745
|
if (arg1 == null) {
|
|
2891
2746
|
return curry2(_omit, __, arg0)
|
|
2892
2747
|
}
|
|
2748
|
+
if (isPromise(arg0)) {
|
|
2749
|
+
return arg0.then(curry2(_omit, __, arg1))
|
|
2750
|
+
}
|
|
2893
2751
|
return _omit(arg0, arg1)
|
|
2894
2752
|
}
|
|
2895
2753
|
|
|
2896
2754
|
const thunkify = (func, ...args) => function thunk() {
|
|
2755
|
+
if (areAnyValuesPromises(args)) {
|
|
2756
|
+
return promiseAll(args).then(curry2(funcApply, func, __))
|
|
2757
|
+
}
|
|
2897
2758
|
return func(...args)
|
|
2898
2759
|
}
|
|
2899
2760
|
|
|
@@ -2904,25 +2765,43 @@ curry.arity = function curryArity_(arity, func, ...args) {
|
|
|
2904
2765
|
}
|
|
2905
2766
|
|
|
2906
2767
|
const rubico = {
|
|
2907
|
-
pipe,
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2768
|
+
pipe, compose,
|
|
2769
|
+
|
|
2770
|
+
tap, forEach,
|
|
2771
|
+
|
|
2772
|
+
switchCase,
|
|
2773
|
+
|
|
2774
|
+
tryCatch,
|
|
2775
|
+
|
|
2776
|
+
all, assign, get, set, pick, omit,
|
|
2777
|
+
|
|
2778
|
+
map, filter, flatMap, reduce, transform,
|
|
2779
|
+
|
|
2780
|
+
and, or, not, some, every,
|
|
2781
|
+
|
|
2912
2782
|
eq, gt, lt, gte, lte,
|
|
2913
|
-
|
|
2914
|
-
curry, __,
|
|
2783
|
+
|
|
2784
|
+
thunkify, always, curry, __,
|
|
2915
2785
|
}
|
|
2916
2786
|
|
|
2917
2787
|
export {
|
|
2918
|
-
pipe,
|
|
2919
|
-
|
|
2920
|
-
|
|
2788
|
+
pipe, compose,
|
|
2789
|
+
|
|
2790
|
+
tap, forEach,
|
|
2791
|
+
|
|
2792
|
+
switchCase,
|
|
2793
|
+
|
|
2794
|
+
tryCatch,
|
|
2795
|
+
|
|
2796
|
+
all, assign, get, set, pick, omit,
|
|
2797
|
+
|
|
2921
2798
|
map, filter, reduce, transform, flatMap,
|
|
2922
|
-
|
|
2799
|
+
|
|
2800
|
+
and, or, not, some, every,
|
|
2801
|
+
|
|
2923
2802
|
eq, gt, lt, gte, lte,
|
|
2924
|
-
|
|
2925
|
-
curry, __,
|
|
2803
|
+
|
|
2804
|
+
thunkify, always, curry, __,
|
|
2926
2805
|
}
|
|
2927
2806
|
|
|
2928
2807
|
export default rubico
|