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
|
@@ -0,0 +1,1322 @@
|
|
|
1
|
+
const timeInLoop = require('../x/timeInLoop')
|
|
2
|
+
const R = require('ramda')
|
|
3
|
+
const _ = require('lodash')
|
|
4
|
+
|
|
5
|
+
const symbolIterator = Symbol.iterator
|
|
6
|
+
|
|
7
|
+
const symbolAsyncIterator = Symbol.asyncIterator
|
|
8
|
+
|
|
9
|
+
const promiseAll = Promise.all.bind(Promise)
|
|
10
|
+
|
|
11
|
+
const isPromise = value => value != null && typeof value.then == 'function'
|
|
12
|
+
|
|
13
|
+
const asyncIteratorToArray = async function (asyncIterator) {
|
|
14
|
+
const result = []
|
|
15
|
+
for await (const item of asyncIterator) {
|
|
16
|
+
result[result.length] = item
|
|
17
|
+
}
|
|
18
|
+
return result
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const asyncArrayReduce = async function (array, reducer, initialValue) {
|
|
22
|
+
let result = initialValue
|
|
23
|
+
for (const item of array) {
|
|
24
|
+
result = await reducer(result, item)
|
|
25
|
+
}
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @name arrayMap
|
|
31
|
+
*
|
|
32
|
+
* @synopsis
|
|
33
|
+
* any -> A, any -> B
|
|
34
|
+
*
|
|
35
|
+
* arrayMap(array Array<A>, mapper A=>Promise|B) -> Promise|Array<B>
|
|
36
|
+
*/
|
|
37
|
+
const arrayMap = function (array, mapper) {
|
|
38
|
+
const arrayLength = array.length,
|
|
39
|
+
result = Array(arrayLength)
|
|
40
|
+
let index = -1, isAsync = false
|
|
41
|
+
while (++index < arrayLength) {
|
|
42
|
+
const resultItem = mapper(array[index])
|
|
43
|
+
if (isPromise(resultItem)) isAsync = true
|
|
44
|
+
result[index] = resultItem
|
|
45
|
+
}
|
|
46
|
+
return isAsync ? promiseAll(result) : result
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @name arrayExtend
|
|
51
|
+
*
|
|
52
|
+
* @synopsis
|
|
53
|
+
* arrayExtend(array Array, values Array) -> array
|
|
54
|
+
*/
|
|
55
|
+
const arrayExtend = (array, values) => {
|
|
56
|
+
const arrayLength = array.length,
|
|
57
|
+
valuesLength = values.length
|
|
58
|
+
let valuesIndex = -1
|
|
59
|
+
while (++valuesIndex < valuesLength) {
|
|
60
|
+
array[arrayLength + valuesIndex] = values[valuesIndex]
|
|
61
|
+
}
|
|
62
|
+
return array
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @name asyncArrayFilter
|
|
67
|
+
*
|
|
68
|
+
* @benchmark
|
|
69
|
+
* asyncArrayFilter1: isOdd: 1e+6: 488.869ms
|
|
70
|
+
* asyncArrayFilter2: isOdd: 1e+6: 491.341ms
|
|
71
|
+
* asyncArrayFilter1: asyncIsOdd: 1e+5: 138.23ms
|
|
72
|
+
* asyncArrayFilter2: asyncIsOdd: 1e+5: 138.915ms
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
const asyncArrayFilter1 = async function (array, predicate) {
|
|
76
|
+
const arrayLength = array.length,
|
|
77
|
+
result = [],
|
|
78
|
+
shouldIncludeItemAtIndex = await arrayMap(array, predicate)
|
|
79
|
+
let index = -1,
|
|
80
|
+
resultIndex = -1
|
|
81
|
+
while (++index < arrayLength) {
|
|
82
|
+
if (shouldIncludeItemAtIndex[index]) {
|
|
83
|
+
result[++resultIndex] = array[index]
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return result
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const asyncArrayFilter2 = async function (array, predicate) {
|
|
90
|
+
const shouldIncludeItemAtIndex = await arrayMap(array, predicate)
|
|
91
|
+
return array.filter((_, index) => shouldIncludeItemAtIndex[index])
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
{
|
|
95
|
+
const array = [1, 2, 3, 4, 5]
|
|
96
|
+
|
|
97
|
+
const isOdd = number => number % 2 == 1
|
|
98
|
+
|
|
99
|
+
const asyncIsOdd = async number => number % 2 == 1
|
|
100
|
+
|
|
101
|
+
// asyncArrayFilter1(array, isOdd).then(console.log)
|
|
102
|
+
// asyncArrayFilter2(array, isOdd).then(console.log)
|
|
103
|
+
// asyncArrayFilter1(array, asyncIsOdd).then(console.log)
|
|
104
|
+
// asyncArrayFilter2(array, asyncIsOdd).then(console.log)
|
|
105
|
+
|
|
106
|
+
// timeInLoop.async('asyncArrayFilter1: isOdd', 1e6, () => asyncArrayFilter1(array, isOdd))
|
|
107
|
+
|
|
108
|
+
// timeInLoop.async('asyncArrayFilter2: isOdd', 1e6, () => asyncArrayFilter2(array, isOdd))
|
|
109
|
+
|
|
110
|
+
// timeInLoop.async('asyncArrayFilter1: asyncIsOdd', 1e5, () => asyncArrayFilter2(array, asyncIsOdd))
|
|
111
|
+
|
|
112
|
+
// timeInLoop.async('asyncArrayFilter2: asyncIsOdd', 1e5, () => asyncArrayFilter2(array, asyncIsOdd))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @name arrayFilter
|
|
117
|
+
*
|
|
118
|
+
* @benchmark
|
|
119
|
+
* nativeArrayFilter: 1e+6: 62.137ms
|
|
120
|
+
* nativeArrayFilterUnary: 1e+6: 64.374ms
|
|
121
|
+
* arrayFilter1: 1e+6: 78.422ms
|
|
122
|
+
* arrayFilter1ScopeTest: 1e+6: 70.671ms
|
|
123
|
+
* arrayFilter1Sync: 1e+6: 68.359ms
|
|
124
|
+
* arrayFilter2: 1e+6: 106.965ms
|
|
125
|
+
* arrayFilter3: 1e+6: 74.412ms
|
|
126
|
+
* arrayFilter30: 1e+6: 74.442ms
|
|
127
|
+
* arrayFilter5: 1e+6: 73.663ms
|
|
128
|
+
* arrayFilter6: 1e+6: 73.266ms
|
|
129
|
+
*
|
|
130
|
+
* arrayFilter1 - async: 1e+5: 222.846ms
|
|
131
|
+
* arrayFilter2 - async: 1e+5: 144.018ms
|
|
132
|
+
* arrayFilter3 - async: 1e+5: 235.657ms
|
|
133
|
+
* arrayFilter30 - async: 1e+5: 245.06ms
|
|
134
|
+
* arrayFilter5 - async: 1e+5: 138.895ms
|
|
135
|
+
* arrayFilter6 - async: 1e+5: 133.806ms
|
|
136
|
+
*
|
|
137
|
+
* @NOTE Bo5
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
const nativeArrayFilter = (array, predicate) => array.filter(predicate)
|
|
141
|
+
|
|
142
|
+
const nativeArrayFilterUnary = (array, predicate) => array.filter(item => predicate(item))
|
|
143
|
+
|
|
144
|
+
const arrayFilter1 = function (array, predicate) {
|
|
145
|
+
const arrayLength = array.length,
|
|
146
|
+
result = []
|
|
147
|
+
let index = -1,
|
|
148
|
+
resultIndex = -1
|
|
149
|
+
while (++index < arrayLength) {
|
|
150
|
+
const item = array[index]
|
|
151
|
+
const shouldIncludeItem = predicate(item)
|
|
152
|
+
if (isPromise(shouldIncludeItem)) {
|
|
153
|
+
return promiseAll([
|
|
154
|
+
shouldIncludeItem,
|
|
155
|
+
asyncArrayFilter1(array.slice(index + 1), predicate),
|
|
156
|
+
]).then(function ([firstShouldIncludeItem, filteredRemainingItems]) {
|
|
157
|
+
if (firstShouldIncludeItem) {
|
|
158
|
+
result[resultIndex + 1] = item
|
|
159
|
+
}
|
|
160
|
+
return arrayExtend(result, filteredRemainingItems)
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
if (shouldIncludeItem) {
|
|
164
|
+
result[++resultIndex] = item
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return result
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const arrayFilter1ScopeTest = function (array, predicate) {
|
|
171
|
+
const arrayLength = array.length,
|
|
172
|
+
result = []
|
|
173
|
+
let index = -1,
|
|
174
|
+
resultIndex = -1
|
|
175
|
+
while (++index < arrayLength) {
|
|
176
|
+
const item = array[index]
|
|
177
|
+
const shouldIncludeItem = predicate(item)
|
|
178
|
+
if (isPromise(shouldIncludeItem)) {
|
|
179
|
+
}
|
|
180
|
+
if (shouldIncludeItem) {
|
|
181
|
+
result[++resultIndex] = item
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return result
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const arrayFilter1Sync = function (array, predicate) {
|
|
188
|
+
const arrayLength = array.length,
|
|
189
|
+
result = []
|
|
190
|
+
let index = -1,
|
|
191
|
+
resultIndex = -1
|
|
192
|
+
while (++index < arrayLength) {
|
|
193
|
+
const item = array[index]
|
|
194
|
+
if (predicate(item)) {
|
|
195
|
+
result[++resultIndex] = item
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return result
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const arrayFilter2 = function (array, predicate) {
|
|
202
|
+
const shouldIncludeItemAtIndex = arrayMap(array, predicate)
|
|
203
|
+
return isPromise(shouldIncludeItemAtIndex)
|
|
204
|
+
? shouldIncludeItemAtIndex.then(res => array.filter((_, index) => res[index]))
|
|
205
|
+
: array.filter((_, index) => shouldIncludeItemAtIndex[index])
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const _arrayFilter3AsyncInterlude1 = function (array, predicate, result, index, resultIndex, firstItem, shouldIncludeItem) {
|
|
209
|
+
return promiseAll([
|
|
210
|
+
shouldIncludeItem,
|
|
211
|
+
asyncArrayFilter1(array.slice(index + 1), predicate),
|
|
212
|
+
]).then(function ([
|
|
213
|
+
resolvedShouldIncludeItem,
|
|
214
|
+
filteredRemainingItems,
|
|
215
|
+
]) {
|
|
216
|
+
if (resolvedShouldIncludeItem) {
|
|
217
|
+
result[resultIndex + 1] = firstItem
|
|
218
|
+
}
|
|
219
|
+
return arrayExtend(result, filteredRemainingItems)
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const arrayFilter3 = function (array, predicate) {
|
|
224
|
+
const arrayLength = array.length,
|
|
225
|
+
result = []
|
|
226
|
+
let index = -1,
|
|
227
|
+
resultIndex = -1
|
|
228
|
+
while (++index < arrayLength) {
|
|
229
|
+
const item = array[index]
|
|
230
|
+
const shouldIncludeItem = predicate(item)
|
|
231
|
+
if (isPromise(shouldIncludeItem)) {
|
|
232
|
+
return _arrayFilter3AsyncInterlude1(array, predicate, result, index, resultIndex, item, shouldIncludeItem)
|
|
233
|
+
}
|
|
234
|
+
if (shouldIncludeItem) {
|
|
235
|
+
result[++resultIndex] = item
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return result
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const asyncArrayFilter1Interlude1 = async function (
|
|
242
|
+
array, predicate, result, index, shouldIncludeItem,
|
|
243
|
+
) {
|
|
244
|
+
const [
|
|
245
|
+
resolvedShouldIncludeItem,
|
|
246
|
+
filteredRemainingItems,
|
|
247
|
+
] = await promiseAll([
|
|
248
|
+
shouldIncludeItem,
|
|
249
|
+
asyncArrayFilter1(array.slice(index + 1), predicate),
|
|
250
|
+
])
|
|
251
|
+
if (resolvedShouldIncludeItem) {
|
|
252
|
+
result[result.length] = array[index]
|
|
253
|
+
}
|
|
254
|
+
return arrayExtend(result, filteredRemainingItems)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const arrayFilter30 = function (array, predicate) {
|
|
258
|
+
const arrayLength = array.length,
|
|
259
|
+
result = []
|
|
260
|
+
let index = -1,
|
|
261
|
+
resultIndex = -1
|
|
262
|
+
while (++index < arrayLength) {
|
|
263
|
+
const item = array[index]
|
|
264
|
+
const shouldIncludeItem = predicate(item)
|
|
265
|
+
if (isPromise(shouldIncludeItem)) {
|
|
266
|
+
return asyncArrayFilter1Interlude1(
|
|
267
|
+
array, predicate, result, index, shouldIncludeItem)
|
|
268
|
+
}
|
|
269
|
+
if (shouldIncludeItem) {
|
|
270
|
+
result[++resultIndex] = item
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return result
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const _shouldIncludeItemsResolver = (
|
|
277
|
+
array, result, index,
|
|
278
|
+
) => function resolvingShouldIncludeItems(shouldIncludeItems) {
|
|
279
|
+
const arrayLength = array.length
|
|
280
|
+
let resultIndex = result.length - 1,
|
|
281
|
+
shouldIncludeItemsIndex = -1
|
|
282
|
+
while (++index < arrayLength) {
|
|
283
|
+
if (shouldIncludeItems[++shouldIncludeItemsIndex]) {
|
|
284
|
+
result[++resultIndex] = array[index]
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return result
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const _arrayExtendMap = function (
|
|
291
|
+
array, values, valuesMapper, valuesIndex,
|
|
292
|
+
) {
|
|
293
|
+
const valuesLength = values.length
|
|
294
|
+
let arrayIndex = array.length - 1
|
|
295
|
+
while (++valuesIndex < valuesLength) {
|
|
296
|
+
array[++arrayIndex] = valuesMapper(values[valuesIndex])
|
|
297
|
+
}
|
|
298
|
+
return array
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const _asyncArrayFilter5 = (
|
|
302
|
+
array, predicate, result, index, shouldIncludeItemPromises,
|
|
303
|
+
) => promiseAll(
|
|
304
|
+
_arrayExtendMap(
|
|
305
|
+
shouldIncludeItemPromises, array, predicate, index)).then(
|
|
306
|
+
_shouldIncludeItemsResolver(array, result, index - 1))
|
|
307
|
+
|
|
308
|
+
const arrayFilter5 = function (array, predicate) {
|
|
309
|
+
const arrayLength = array.length,
|
|
310
|
+
result = []
|
|
311
|
+
let index = -1,
|
|
312
|
+
resultIndex = -1
|
|
313
|
+
while (++index < arrayLength) {
|
|
314
|
+
const item = array[index]
|
|
315
|
+
const shouldIncludeItem = predicate(item)
|
|
316
|
+
if (isPromise(shouldIncludeItem)) {
|
|
317
|
+
return _asyncArrayFilter5(
|
|
318
|
+
array, predicate, result, index, [shouldIncludeItem])
|
|
319
|
+
}
|
|
320
|
+
if (shouldIncludeItem) {
|
|
321
|
+
result[++resultIndex] = item
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return result
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const arrayExtendMap = function (
|
|
328
|
+
array, values, valuesMapper, valuesIndex,
|
|
329
|
+
) {
|
|
330
|
+
const valuesLength = values.length
|
|
331
|
+
let arrayIndex = array.length - 1
|
|
332
|
+
while (++valuesIndex < valuesLength) {
|
|
333
|
+
array[++arrayIndex] = valuesMapper(values[valuesIndex])
|
|
334
|
+
}
|
|
335
|
+
return array
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const arrayFilterConditionsResolver = (
|
|
339
|
+
array, result, index,
|
|
340
|
+
) => function resolvingShouldIncludeItems(shouldIncludeItems) {
|
|
341
|
+
const arrayLength = array.length
|
|
342
|
+
let resultIndex = result.length - 1,
|
|
343
|
+
shouldIncludeItemsIndex = -1
|
|
344
|
+
while (++index < arrayLength) {
|
|
345
|
+
if (shouldIncludeItems[++shouldIncludeItemsIndex]) {
|
|
346
|
+
result[++resultIndex] = array[index]
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return result
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const arrayFilter6 = function (array, predicate) {
|
|
353
|
+
const arrayLength = array.length,
|
|
354
|
+
result = []
|
|
355
|
+
let index = -1,
|
|
356
|
+
resultIndex = -1
|
|
357
|
+
while (++index < arrayLength) {
|
|
358
|
+
const item = array[index]
|
|
359
|
+
const shouldIncludeItem = predicate(item)
|
|
360
|
+
if (isPromise(shouldIncludeItem)) {
|
|
361
|
+
return promiseAll(
|
|
362
|
+
arrayExtendMap(
|
|
363
|
+
[shouldIncludeItem], array, predicate, index)).then(
|
|
364
|
+
arrayFilterConditionsResolver(array, result, index - 1))
|
|
365
|
+
}
|
|
366
|
+
if (shouldIncludeItem) {
|
|
367
|
+
result[++resultIndex] = item
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return result
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
{
|
|
374
|
+
const array = [1, 2, 3, 4, 5]
|
|
375
|
+
|
|
376
|
+
const isOdd = number => number % 2 == 1
|
|
377
|
+
|
|
378
|
+
const asyncIsOdd = async number => number % 2 == 1
|
|
379
|
+
|
|
380
|
+
// console.log(nativeArrayFilter(array, isOdd))
|
|
381
|
+
// console.log(nativeArrayFilterUnary(array, isOdd))
|
|
382
|
+
// console.log(arrayFilter1(array, isOdd))
|
|
383
|
+
// console.log(arrayFilter1ScopeTest(array, isOdd))
|
|
384
|
+
// console.log(arrayFilter1Sync(array, isOdd))
|
|
385
|
+
// console.log(arrayFilter2(array, isOdd))
|
|
386
|
+
// console.log(arrayFilter3(array, isOdd))
|
|
387
|
+
// console.log(arrayFilter5(array, isOdd))
|
|
388
|
+
// console.log(arrayFilter6(array, isOdd))
|
|
389
|
+
// arrayFilter3(array, asyncIsOdd).then(console.log)
|
|
390
|
+
// arrayFilter30(array, asyncIsOdd).then(console.log)
|
|
391
|
+
// arrayFilter5(array, asyncIsOdd).then(console.log)
|
|
392
|
+
// arrayFilter6(array, asyncIsOdd).then(console.log)
|
|
393
|
+
|
|
394
|
+
// timeInLoop('nativeArrayFilter', 1e6, () => nativeArrayFilter(array, isOdd))
|
|
395
|
+
|
|
396
|
+
// timeInLoop('nativeArrayFilterUnary', 1e6, () => nativeArrayFilterUnary(array, isOdd))
|
|
397
|
+
|
|
398
|
+
// timeInLoop('arrayFilter1', 1e6, () => arrayFilter1(array, isOdd))
|
|
399
|
+
|
|
400
|
+
// timeInLoop('arrayFilter1ScopeTest', 1e6, () => arrayFilter1ScopeTest(array, isOdd))
|
|
401
|
+
|
|
402
|
+
// timeInLoop('arrayFilter1Sync', 1e6, () => arrayFilter1Sync(array, isOdd))
|
|
403
|
+
|
|
404
|
+
// timeInLoop('arrayFilter2', 1e6, () => arrayFilter2(array, isOdd))
|
|
405
|
+
|
|
406
|
+
// timeInLoop('arrayFilter3', 1e6, () => arrayFilter3(array, isOdd))
|
|
407
|
+
|
|
408
|
+
// timeInLoop('arrayFilter30', 1e6, () => arrayFilter30(array, isOdd))
|
|
409
|
+
|
|
410
|
+
// timeInLoop('arrayFilter5', 1e6, () => arrayFilter5(array, isOdd))
|
|
411
|
+
|
|
412
|
+
// timeInLoop('arrayFilter6', 1e6, () => arrayFilter6(array, isOdd))
|
|
413
|
+
|
|
414
|
+
// timeInLoop.async('arrayFilter1 - async', 1e5, () => arrayFilter1(array, asyncIsOdd))
|
|
415
|
+
|
|
416
|
+
// timeInLoop.async('arrayFilter2 - async', 1e5, () => arrayFilter2(array, asyncIsOdd))
|
|
417
|
+
|
|
418
|
+
// timeInLoop.async('arrayFilter3 - async', 1e5, () => arrayFilter3(array, asyncIsOdd))
|
|
419
|
+
|
|
420
|
+
// timeInLoop.async('arrayFilter30 - async', 1e5, () => arrayFilter30(array, asyncIsOdd))
|
|
421
|
+
|
|
422
|
+
// timeInLoop.async('arrayFilter5 - async', 1e5, () => arrayFilter5(array, asyncIsOdd))
|
|
423
|
+
|
|
424
|
+
// timeInLoop.async('arrayFilter6 - async', 1e5, () => arrayFilter6(array, asyncIsOdd))
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* @name objectFilter
|
|
429
|
+
*
|
|
430
|
+
* @benchmark
|
|
431
|
+
* objectFilter0: 1e+6: 227.187ms
|
|
432
|
+
* objectFilter1: 1e+6: 138.815ms
|
|
433
|
+
* objectFilter2: 1e+6: 136.23ms
|
|
434
|
+
* objectFilter3: 1e+6: 136.15ms
|
|
435
|
+
* objectFilter5: 1e+6: 137.69ms
|
|
436
|
+
*
|
|
437
|
+
* objectFilter0: async: 1e+5: 209.209ms
|
|
438
|
+
* objectFilter1: async: 1e+5: 192.017ms
|
|
439
|
+
* objectFilter2: async: 1e+5: 186.799ms
|
|
440
|
+
* objectFilter3: async: 1e+5: 198.939ms
|
|
441
|
+
* objectFilter5: async: 1e+5: 190.143ms
|
|
442
|
+
*/
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
const objectFilter0 = function (object, predicate) {
|
|
446
|
+
const result = {},
|
|
447
|
+
promises = []
|
|
448
|
+
for (const key in object) {
|
|
449
|
+
const item = object[key]
|
|
450
|
+
const shouldIncludeItem = predicate(item)
|
|
451
|
+
if (isPromise(shouldIncludeItem)) {
|
|
452
|
+
promises[promises.length] = shouldIncludeItem.then(
|
|
453
|
+
function (res) {
|
|
454
|
+
if (res) {
|
|
455
|
+
result[key] = object[key]
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
)
|
|
459
|
+
} else if (shouldIncludeItem) {
|
|
460
|
+
result[key] = item
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return promises.length == 0 ? result : promiseAll(promises).then(() => result)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const _pushSetIfShouldIncludeItemPromise = function (
|
|
467
|
+
object, result, promises, key, shouldIncludeItemPromise,
|
|
468
|
+
) {
|
|
469
|
+
promises[promises.length] = shouldIncludeItemPromise.then(
|
|
470
|
+
function (shouldIncludeItem) {
|
|
471
|
+
if (shouldIncludeItem) {
|
|
472
|
+
result[key] = object[key]
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
)
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const _tapPossiblePromiseAllThenResolve = (promises, value) => promises.length == 0
|
|
479
|
+
? value
|
|
480
|
+
: promiseAll(promises).then(() => value)
|
|
481
|
+
|
|
482
|
+
const objectFilter1 = function (object, predicate) {
|
|
483
|
+
const result = {},
|
|
484
|
+
promises = []
|
|
485
|
+
for (const key in object) {
|
|
486
|
+
const item = object[key]
|
|
487
|
+
const shouldIncludeItem = predicate(item)
|
|
488
|
+
if (isPromise(shouldIncludeItem)) {
|
|
489
|
+
_pushSetIfShouldIncludeItemPromise(
|
|
490
|
+
object, result, promises, key, shouldIncludeItem)
|
|
491
|
+
} else if (shouldIncludeItem) {
|
|
492
|
+
result[key] = item
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return _tapPossiblePromiseAllThenResolve(promises, result)
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const _setIfShouldIncludeItem = (
|
|
499
|
+
object, result, key,
|
|
500
|
+
) => function settingIfShouldIncludeItem(shouldIncludeItem) {
|
|
501
|
+
if (shouldIncludeItem) {
|
|
502
|
+
result[key] = object[key]
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const _pushSetIfShouldIncludeItemPromiseRefactorInner = function (
|
|
507
|
+
object, result, promises, key, shouldIncludeItemPromise,
|
|
508
|
+
) {
|
|
509
|
+
promises[promises.length] = shouldIncludeItemPromise.then(
|
|
510
|
+
_setIfShouldIncludeItem(object, result, key))
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const objectFilter2 = function (object, predicate) {
|
|
514
|
+
const result = {},
|
|
515
|
+
promises = []
|
|
516
|
+
for (const key in object) {
|
|
517
|
+
const item = object[key]
|
|
518
|
+
const shouldIncludeItem = predicate(item)
|
|
519
|
+
if (isPromise(shouldIncludeItem)) {
|
|
520
|
+
_pushSetIfShouldIncludeItemPromiseRefactorInner(
|
|
521
|
+
object, result, promises, key, shouldIncludeItem)
|
|
522
|
+
} else if (shouldIncludeItem) {
|
|
523
|
+
result[key] = item
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return _tapPossiblePromiseAllThenResolve(promises, result)
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const nativePromiseThen = Promise.prototype.then
|
|
530
|
+
|
|
531
|
+
const promiseThen = (promise, func) => nativePromiseThen.call(promise, func)
|
|
532
|
+
|
|
533
|
+
const _pushSetIfShouldIncludeItemPromiseRefactorInnerPromiseThen = function (
|
|
534
|
+
object, result, promises, key, shouldIncludeItemPromise,
|
|
535
|
+
) {
|
|
536
|
+
const setIfShouldIncludeItem = _setIfShouldIncludeItem(object, result, key)
|
|
537
|
+
promises[promises.length] = promiseThen(
|
|
538
|
+
shouldIncludeItemPromise, setIfShouldIncludeItem)
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const objectFilter3 = function (object, predicate) {
|
|
542
|
+
const result = {},
|
|
543
|
+
promises = []
|
|
544
|
+
for (const key in object) {
|
|
545
|
+
const item = object[key]
|
|
546
|
+
const shouldIncludeItem = predicate(item)
|
|
547
|
+
if (isPromise(shouldIncludeItem)) {
|
|
548
|
+
_pushSetIfShouldIncludeItemPromiseRefactorInnerPromiseThen(
|
|
549
|
+
object, result, promises, key, shouldIncludeItem)
|
|
550
|
+
} else if (shouldIncludeItem) {
|
|
551
|
+
result[key] = item
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return _tapPossiblePromiseAllThenResolve(promises, result)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const objectSetConditionalResolver = (
|
|
558
|
+
object, result, key,
|
|
559
|
+
) => function settingValueIfTruthy(shouldIncludeItem) {
|
|
560
|
+
if (shouldIncludeItem) {
|
|
561
|
+
result[key] = object[key]
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const always = value => function getter() { return value }
|
|
566
|
+
|
|
567
|
+
const objectFilter5 = function (object, predicate) {
|
|
568
|
+
const result = {},
|
|
569
|
+
promises = []
|
|
570
|
+
for (const key in object) {
|
|
571
|
+
const item = object[key]
|
|
572
|
+
const shouldIncludeItem = predicate(item)
|
|
573
|
+
if (isPromise(shouldIncludeItem)) {
|
|
574
|
+
promises[promises.length] = shouldIncludeItem.then(
|
|
575
|
+
objectSetConditionalResolver(object, result, key))
|
|
576
|
+
} else if (shouldIncludeItem) {
|
|
577
|
+
result[key] = item
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return promises.length == 0
|
|
581
|
+
? result
|
|
582
|
+
: promiseAll(promises).then(always(result))
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
{
|
|
586
|
+
const object = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
|
587
|
+
|
|
588
|
+
const isOdd = number => number % 2 == 1
|
|
589
|
+
|
|
590
|
+
const asyncIsOdd = async number => number % 2 == 1
|
|
591
|
+
|
|
592
|
+
// console.log(objectFilter0(object, isOdd))
|
|
593
|
+
// console.log(objectFilter1(object, isOdd))
|
|
594
|
+
// console.log(objectFilter2(object, isOdd))
|
|
595
|
+
// console.log(objectFilter3(object, isOdd))
|
|
596
|
+
// console.log(objectFilter5(object, isOdd))
|
|
597
|
+
// objectFilter3(object, asyncIsOdd).then(console.log)
|
|
598
|
+
// objectFilter5(object, asyncIsOdd).then(console.log)
|
|
599
|
+
|
|
600
|
+
// timeInLoop('objectFilter0', 1e6, () => objectFilter0(object, isOdd))
|
|
601
|
+
|
|
602
|
+
// timeInLoop('objectFilter1', 1e6, () => objectFilter1(object, isOdd))
|
|
603
|
+
|
|
604
|
+
// timeInLoop('objectFilter2', 1e6, () => objectFilter2(object, isOdd))
|
|
605
|
+
|
|
606
|
+
// timeInLoop('objectFilter3', 1e6, () => objectFilter3(object, isOdd))
|
|
607
|
+
|
|
608
|
+
// timeInLoop('objectFilter5', 1e6, () => objectFilter5(object, isOdd))
|
|
609
|
+
|
|
610
|
+
// timeInLoop.async('objectFilter0: async', 1e5, () => objectFilter0(object, asyncIsOdd))
|
|
611
|
+
|
|
612
|
+
// timeInLoop.async('objectFilter1: async', 1e5, () => objectFilter1(object, asyncIsOdd))
|
|
613
|
+
|
|
614
|
+
// timeInLoop.async('objectFilter2: async', 1e5, () => objectFilter2(object, asyncIsOdd))
|
|
615
|
+
|
|
616
|
+
// timeInLoop.async('objectFilter3: async', 1e5, () => objectFilter3(object, asyncIsOdd))
|
|
617
|
+
|
|
618
|
+
// timeInLoop.async('objectFilter5: async', 1e5, () => objectFilter5(object, asyncIsOdd))
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* @name generatorFunctionFilter
|
|
623
|
+
*
|
|
624
|
+
* @benchmark
|
|
625
|
+
* generatorFunctionFilter1: 1e+5: 97.002ms
|
|
626
|
+
*/
|
|
627
|
+
|
|
628
|
+
const generatorFunctionFilter1 = (
|
|
629
|
+
generatorFunction, predicate,
|
|
630
|
+
) => function* filteringGeneratorFunction(...args) {
|
|
631
|
+
for (const item of generatorFunction(...args)) {
|
|
632
|
+
if (predicate(item)) {
|
|
633
|
+
yield item
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
{
|
|
639
|
+
const numbers = function* () {
|
|
640
|
+
yield 1; yield 2; yield 3; yield 4; yield 5
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
const isOdd = number => number % 2 == 1
|
|
644
|
+
|
|
645
|
+
// console.log([...generatorFunctionFilter1(numbers, isOdd)()])
|
|
646
|
+
|
|
647
|
+
const _generatorFunctionFilter1 = generatorFunctionFilter1(numbers, isOdd)
|
|
648
|
+
|
|
649
|
+
// timeInLoop('generatorFunctionFilter1', 1e5, () => [..._generatorFunctionFilter1()])
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* @name FilteringIterator
|
|
654
|
+
*
|
|
655
|
+
* @benchmark
|
|
656
|
+
* iteratorFilter0: 1e+5: 85.751ms
|
|
657
|
+
* iteratorFilter1: 1e+5: 70.104ms
|
|
658
|
+
*/
|
|
659
|
+
|
|
660
|
+
const iteratorFilter0 = function* (iter, predicate) {
|
|
661
|
+
for (const item of iter) {
|
|
662
|
+
if (predicate(item)) {
|
|
663
|
+
yield item
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const FilteringIterator = function (iter, predicate) {
|
|
669
|
+
this.iter = iter
|
|
670
|
+
this.predicate = predicate
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
FilteringIterator.prototype[symbolIterator] = function filteringValues() {
|
|
674
|
+
return this
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
FilteringIterator.prototype.next = function next() {
|
|
678
|
+
const thisIterNext = this.iter.next.bind(this.iter),
|
|
679
|
+
thisPredicate = this.predicate
|
|
680
|
+
let iteration = this.iter.next()
|
|
681
|
+
while (!iteration.done) {
|
|
682
|
+
const { value } = iteration
|
|
683
|
+
if (thisPredicate(value)) {
|
|
684
|
+
return { value, done: false }
|
|
685
|
+
}
|
|
686
|
+
iteration = thisIterNext()
|
|
687
|
+
}
|
|
688
|
+
return { value: undefined, done: true }
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
{
|
|
692
|
+
const isOdd = number => number % 2 == 1
|
|
693
|
+
|
|
694
|
+
const numbers = function* () { let i = 0; while (++i < 6) yield i }
|
|
695
|
+
|
|
696
|
+
const iteratorFilter1 = (iter, predicate) => new FilteringIterator(iter, predicate)
|
|
697
|
+
|
|
698
|
+
// console.log([...iteratorFilter0(numbers(), isOdd)])
|
|
699
|
+
// console.log([...iteratorFilter1(numbers(), isOdd)])
|
|
700
|
+
|
|
701
|
+
// timeInLoop('iteratorFilter0', 1e5, () => [...iteratorFilter0(numbers(), isOdd)])
|
|
702
|
+
|
|
703
|
+
// timeInLoop('iteratorFilter1', 1e5, () => [...iteratorFilter1(numbers(), isOdd)])
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* @name asyncGeneratorFunctionFilter
|
|
708
|
+
*
|
|
709
|
+
* @benchmark
|
|
710
|
+
* asyncGeneratorFunctionFilter1: 1e+5: 367.211ms
|
|
711
|
+
*
|
|
712
|
+
* asyncGeneratorFunctionFilter1AsyncPredicate: 1e+5: 427.324ms
|
|
713
|
+
*/
|
|
714
|
+
|
|
715
|
+
const asyncGeneratorFunctionFilter1 = function (asyncGeneratorFunction, predicate) {
|
|
716
|
+
return async function* filteringAsyncGeneratorFunction(...args) {
|
|
717
|
+
for await (const item of asyncGeneratorFunction(...args)) {
|
|
718
|
+
const shouldIncludeItem = predicate(item)
|
|
719
|
+
if (
|
|
720
|
+
isPromise(shouldIncludeItem)
|
|
721
|
+
? await shouldIncludeItem
|
|
722
|
+
: shouldIncludeItem
|
|
723
|
+
) {
|
|
724
|
+
yield item
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
{
|
|
731
|
+
const asyncNumbers = async function* () { let i = 0; while (++i < 6) yield i }
|
|
732
|
+
|
|
733
|
+
const isOdd = number => number % 2 == 1
|
|
734
|
+
|
|
735
|
+
const asyncIsOdd = async number => number % 2 == 1
|
|
736
|
+
|
|
737
|
+
const _asyncGeneratorFilteringFunction1 = asyncGeneratorFunctionFilter1(asyncNumbers, isOdd)
|
|
738
|
+
|
|
739
|
+
const _asyncGeneratorFilteringFunction1AsyncPredicate = asyncGeneratorFunctionFilter1(asyncNumbers, asyncIsOdd)
|
|
740
|
+
|
|
741
|
+
// asyncIteratorToArray(_asyncGeneratorFilteringFunction1()).then(console.log)
|
|
742
|
+
// asyncIteratorToArray(_asyncGeneratorFilteringFunction1Async()).then(console.log)
|
|
743
|
+
|
|
744
|
+
// timeInLoop.async('asyncGeneratorFunctionFilter1', 1e5, () => asyncIteratorToArray(_asyncGeneratorFilteringFunction1()))
|
|
745
|
+
|
|
746
|
+
// timeInLoop.async('asyncGeneratorFunctionFilter1AsyncPredicate', 1e5, () => asyncIteratorToArray(_asyncGeneratorFilteringFunction1AsyncPredicate()))
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* @name FilteringAsyncIterator
|
|
751
|
+
*
|
|
752
|
+
* @benchmark
|
|
753
|
+
* asyncIteratorFilter0: 1e+5: 431.374ms
|
|
754
|
+
* asyncIteratorFilter1: 1e+5: 316.587ms
|
|
755
|
+
*
|
|
756
|
+
* asyncIteratorFilter0: AsyncPredicate: 1e+5: 434.51ms
|
|
757
|
+
* asyncIteratorFilter1: AsyncPredicate: 1e+5: 371.103ms
|
|
758
|
+
*/
|
|
759
|
+
|
|
760
|
+
const asyncIteratorFilter0 = async function* (asyncIter, predicate) {
|
|
761
|
+
for await (const item of asyncIter) {
|
|
762
|
+
if (await predicate(item)) {
|
|
763
|
+
yield item
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const FilteringAsyncIterator = function (asyncIter, predicate) {
|
|
769
|
+
this.asyncIter = asyncIter
|
|
770
|
+
this.predicate = predicate
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
FilteringAsyncIterator.prototype[symbolAsyncIterator] = function filteringValues() {
|
|
774
|
+
return this
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
FilteringAsyncIterator.prototype.next = async function next() {
|
|
778
|
+
const thisIterNext = this.asyncIter.next.bind(this.asyncIter),
|
|
779
|
+
thisPredicate = this.predicate
|
|
780
|
+
let iteration = await thisIterNext()
|
|
781
|
+
while (!iteration.done) {
|
|
782
|
+
const { value } = iteration
|
|
783
|
+
const shouldIncludeItem = thisPredicate(value)
|
|
784
|
+
if (
|
|
785
|
+
isPromise(shouldIncludeItem)
|
|
786
|
+
? await shouldIncludeItem
|
|
787
|
+
: shouldIncludeItem
|
|
788
|
+
) {
|
|
789
|
+
return { value, done: false }
|
|
790
|
+
}
|
|
791
|
+
iteration = await thisIterNext()
|
|
792
|
+
}
|
|
793
|
+
return { value: undefined, done: true }
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
const asyncIteratorFilter1 = (iter, predicate) => new FilteringAsyncIterator(iter, predicate)
|
|
797
|
+
|
|
798
|
+
{
|
|
799
|
+
const isOdd = number => number % 2 == 1
|
|
800
|
+
|
|
801
|
+
const asyncIsOdd = async number => number % 2 == 1
|
|
802
|
+
|
|
803
|
+
const asyncNumbers = async function* () { let i = 0; while (++i < 6) yield i }
|
|
804
|
+
|
|
805
|
+
// asyncIteratorToArray(asyncIteratorFilter0(asyncNumbers(), isOdd)).then(res => console.log('asyncIteratorFilter0', res))
|
|
806
|
+
// asyncIteratorToArray(asyncIteratorFilter1(asyncNumbers(), isOdd)).then(res => console.log('asyncIteratorFilter1', res))
|
|
807
|
+
|
|
808
|
+
// timeInLoop.async('asyncIteratorFilter0', 1e5, () => asyncIteratorToArray(asyncIteratorFilter0(asyncNumbers(), isOdd)))
|
|
809
|
+
|
|
810
|
+
// timeInLoop.async('asyncIteratorFilter1', 1e5, () => asyncIteratorToArray(asyncIteratorFilter1(asyncNumbers(), isOdd)))
|
|
811
|
+
|
|
812
|
+
//timeInLoop.async('asyncIteratorFilter0: AsyncPredicate', 1e5, () => asyncIteratorToArray(asyncIteratorFilter0(asyncNumbers(), asyncIsOdd)))
|
|
813
|
+
|
|
814
|
+
// timeInLoop.async('asyncIteratorFilter1: AsyncPredicate', 1e5, () => asyncIteratorToArray(asyncIteratorFilter1(asyncNumbers(), asyncIsOdd)))
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* @name reducerFilter
|
|
819
|
+
*
|
|
820
|
+
* @benchmark
|
|
821
|
+
* reducerFilter0: 1e+5: 247.22ms
|
|
822
|
+
* reducerFilter1: 1e+5: 242.314ms
|
|
823
|
+
* reducerFilter2: 1e+5: 233.471ms
|
|
824
|
+
*
|
|
825
|
+
* reducerFilter0: async: 1e+5: 304.144ms
|
|
826
|
+
* reducerFilter1: async: 1e+5: 330.365ms
|
|
827
|
+
* reducerFilter2: async: 1e+5: 302.424ms
|
|
828
|
+
*/
|
|
829
|
+
|
|
830
|
+
const reducerFilter0 = (
|
|
831
|
+
reducer, predicate,
|
|
832
|
+
) => function filteringReducer(accumulator, item) {
|
|
833
|
+
const shouldIncludeItem = predicate(item)
|
|
834
|
+
if (isPromise(shouldIncludeItem)) {
|
|
835
|
+
return shouldIncludeItem.then(res =>
|
|
836
|
+
res ? reducer(accumulator, item) : accumulator)
|
|
837
|
+
}
|
|
838
|
+
return shouldIncludeItem ? reducer(accumulator, item) : accumulator
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
const _asyncReducerFiltration = async function (
|
|
842
|
+
reducer, accumulator, item, shouldIncludeItemPromise,
|
|
843
|
+
) {
|
|
844
|
+
return await shouldIncludeItemPromise
|
|
845
|
+
? reducer(accumulator, item)
|
|
846
|
+
: accumulator
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
const reducerFilter1 = (
|
|
850
|
+
reducer, predicate,
|
|
851
|
+
) => function filteringReducer(accumulator, item) {
|
|
852
|
+
const shouldIncludeItem = predicate(item)
|
|
853
|
+
if (isPromise(shouldIncludeItem)) {
|
|
854
|
+
return _asyncReducerFiltration(
|
|
855
|
+
reducer, accumulator, item, shouldIncludeItem)
|
|
856
|
+
}
|
|
857
|
+
return shouldIncludeItem ? reducer(accumulator, item) : accumulator
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
const _asyncReducerFiltrationPromise = (
|
|
861
|
+
reducer, accumulator, item, shouldIncludeItemPromise,
|
|
862
|
+
) => shouldIncludeItemPromise.then(
|
|
863
|
+
res => res ? reducer(accumulator, item) : accumulator)
|
|
864
|
+
|
|
865
|
+
const reducerFilter2 = (
|
|
866
|
+
reducer, predicate,
|
|
867
|
+
) => function filteringReducer(accumulator, item) {
|
|
868
|
+
const shouldIncludeItem = predicate(item)
|
|
869
|
+
if (isPromise(shouldIncludeItem)) {
|
|
870
|
+
return _asyncReducerFiltrationPromise(
|
|
871
|
+
reducer, accumulator, item, shouldIncludeItem)
|
|
872
|
+
}
|
|
873
|
+
return shouldIncludeItem ? reducer(accumulator, item) : accumulator
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
{
|
|
877
|
+
const numbers = [1, 2, 3, 4, 5]
|
|
878
|
+
|
|
879
|
+
const arrayConcat = (arrA, arrB) => arrA.concat(arrB)
|
|
880
|
+
|
|
881
|
+
const isOdd = number => number % 2 == 1
|
|
882
|
+
|
|
883
|
+
const asyncIsOdd = async number => number % 2 == 1
|
|
884
|
+
|
|
885
|
+
// console.log(numbers.reduce(reducerFilter0(arrayConcat, isOdd), []))
|
|
886
|
+
// console.log(numbers.reduce(reducerFilter1(arrayConcat, isOdd), []))
|
|
887
|
+
// console.log(numbers.reduce(reducerFilter2(arrayConcat, isOdd), []))
|
|
888
|
+
// asyncArrayReduce(numbers, reducerFilter0(arrayConcat, asyncIsOdd), []).then(console.log)
|
|
889
|
+
// asyncArrayReduce(numbers, reducerFilter1(arrayConcat, asyncIsOdd), []).then(console.log)
|
|
890
|
+
// asyncArrayReduce(numbers, reducerFilter2(arrayConcat, asyncIsOdd), []).then(console.log)
|
|
891
|
+
|
|
892
|
+
// timeInLoop.async('reducerFilter0', 1e5, () => asyncArrayReduce(numbers, reducerFilter0(arrayConcat, isOdd), []))
|
|
893
|
+
|
|
894
|
+
// timeInLoop.async('reducerFilter1', 1e5, () => asyncArrayReduce(numbers, reducerFilter1(arrayConcat, isOdd), []))
|
|
895
|
+
|
|
896
|
+
// timeInLoop.async('reducerFilter2', 1e5, () => asyncArrayReduce(numbers, reducerFilter2(arrayConcat, isOdd), []))
|
|
897
|
+
|
|
898
|
+
// timeInLoop.async('reducerFilter0: async', 1e5, () => asyncArrayReduce(numbers, reducerFilter0(arrayConcat, asyncIsOdd), []))
|
|
899
|
+
|
|
900
|
+
// timeInLoop.async('reducerFilter1: async', 1e5, () => asyncArrayReduce(numbers, reducerFilter1(arrayConcat, asyncIsOdd), []))
|
|
901
|
+
|
|
902
|
+
// timeInLoop.async('reducerFilter2: async', 1e5, () => asyncArrayReduce(numbers, reducerFilter2(arrayConcat, asyncIsOdd), []))
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* @name arrayFilterWithIndex
|
|
907
|
+
*
|
|
908
|
+
* @benchmark
|
|
909
|
+
* arrayFilterWithIndex0: 1e+6: 120.52ms
|
|
910
|
+
* arrayFilterWithIndex1: 1e+6: 73.923ms
|
|
911
|
+
* arrayFilterWithIndex2: 1e+6: 75.2ms
|
|
912
|
+
* arrayFilterWithIndex3: 1e+6: 73.448ms
|
|
913
|
+
* arrayFilterWithIndex30: 1e+6: 74.345ms
|
|
914
|
+
* arrayFilterWithIndex31: 1e+6: 76.641ms
|
|
915
|
+
* arrayFilterWithIndex32: 1e+6: 74.355ms
|
|
916
|
+
* arrayFilterWithIndex33: 1e+6: 73.379ms
|
|
917
|
+
*
|
|
918
|
+
* arrayFilterWithIndex0 - async: 1e+5: 129.733ms
|
|
919
|
+
* arrayFilterWithIndex1 - async: 1e+5: 249.433ms
|
|
920
|
+
* arrayFilterWithIndex2 - async: 1e+5: 279.556ms
|
|
921
|
+
* arrayFilterWithIndex3 - async: 1e+5: 153.114ms
|
|
922
|
+
* arrayFilterWithIndex30 - async: 1e+5: 154.646ms
|
|
923
|
+
* arrayFilterWithIndex31 - async: 1e+5: 139.632ms
|
|
924
|
+
* arrayFilterWithIndex32 - async: 1e+5: 136.089ms
|
|
925
|
+
* arrayFilterWithIndex33 - async: 1e+5: 135.066ms
|
|
926
|
+
*/
|
|
927
|
+
|
|
928
|
+
const arrayFilterWithIndex0 = function (array, predicate) {
|
|
929
|
+
let isAsync = false
|
|
930
|
+
const shouldIncludeItemArray = array.map(function (item) {
|
|
931
|
+
const shouldIncludeItem = predicate(item)
|
|
932
|
+
if (isPromise(shouldIncludeItem)) isAsync = true
|
|
933
|
+
return shouldIncludeItem
|
|
934
|
+
})
|
|
935
|
+
return isAsync
|
|
936
|
+
? promiseAll(shouldIncludeItemArray).then(
|
|
937
|
+
res => array.filter((_, index) => res[index]))
|
|
938
|
+
: array.filter((_, index) => shouldIncludeItemArray[index])
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
const arrayMapWithIndex = function (array, mapper) {
|
|
942
|
+
const arrayLength = array.length,
|
|
943
|
+
result = Array(arrayLength)
|
|
944
|
+
let index = -1, isAsync = false
|
|
945
|
+
while (++index < arrayLength) {
|
|
946
|
+
const resultItem = mapper(array[index], index, array)
|
|
947
|
+
if (isPromise(resultItem)) isAsync = true
|
|
948
|
+
result[index] = resultItem
|
|
949
|
+
}
|
|
950
|
+
return isAsync ? promiseAll(result) : result
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
const asyncArrayFilterWithIndex1 = async function (array, predicate) {
|
|
954
|
+
const arrayLength = array.length,
|
|
955
|
+
result = [],
|
|
956
|
+
shouldIncludeItemAtIndex = await arrayMapWithIndex(array, predicate)
|
|
957
|
+
let index = -1,
|
|
958
|
+
resultIndex = -1
|
|
959
|
+
while (++index < arrayLength) {
|
|
960
|
+
if (shouldIncludeItemAtIndex[index]) {
|
|
961
|
+
result[++resultIndex] = array[index]
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
return result
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
const asyncArrayFilterWithIndexInterlude1 = async function (
|
|
968
|
+
array, predicate, result, index, shouldIncludeFirstItemPromise,
|
|
969
|
+
) {
|
|
970
|
+
const [
|
|
971
|
+
shouldIncludeFirstItem,
|
|
972
|
+
filteredRemainingItems,
|
|
973
|
+
] = await promiseAll([
|
|
974
|
+
shouldIncludeFirstItemPromise,
|
|
975
|
+
asyncArrayFilterWithIndex1(array.slice(index + 1), predicate),
|
|
976
|
+
])
|
|
977
|
+
if (shouldIncludeFirstItem) {
|
|
978
|
+
result[result.length] = array[index]
|
|
979
|
+
}
|
|
980
|
+
return arrayExtend(result, filteredRemainingItems)
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
const arrayFilterWithIndex1 = function (array, predicate) {
|
|
984
|
+
const arrayLength = array.length,
|
|
985
|
+
result = []
|
|
986
|
+
let index = -1,
|
|
987
|
+
resultIndex = -1
|
|
988
|
+
while (++index < arrayLength) {
|
|
989
|
+
const item = array[index]
|
|
990
|
+
const shouldIncludeItem = predicate(item, index, array)
|
|
991
|
+
if (isPromise(shouldIncludeItem)) {
|
|
992
|
+
return asyncArrayFilterWithIndexInterlude1(
|
|
993
|
+
array, predicate, result, index, shouldIncludeItem)
|
|
994
|
+
}
|
|
995
|
+
if (shouldIncludeItem) {
|
|
996
|
+
result[++resultIndex] = item
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
return result
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
const _arraySetter = (array, index) => function arraySet(value) {
|
|
1003
|
+
array[index] = value
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
const _asyncSliceMapWithIndexContinued = async function (
|
|
1007
|
+
array, toIndex, mapper, result, index, resultIndex, promises,
|
|
1008
|
+
) {
|
|
1009
|
+
let promisesIndex = promises.length - 1
|
|
1010
|
+
while (++index < toIndex) {
|
|
1011
|
+
const resultItem = mapper(array[index], index, array)
|
|
1012
|
+
if (isPromise(resultItem)) {
|
|
1013
|
+
promises[++promisesIndex] = resultItem.then(
|
|
1014
|
+
_arraySetter(result, ++resultIndex))
|
|
1015
|
+
} else {
|
|
1016
|
+
result[++resultIndex] = result
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
if (promisesIndex == -1) {
|
|
1020
|
+
return result
|
|
1021
|
+
}
|
|
1022
|
+
await promiseAll(promises)
|
|
1023
|
+
return result
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
const sliceMapWithIndex = function (array, fromIndex, toIndex, mapper) {
|
|
1027
|
+
const result = Array(toIndex - fromIndex)
|
|
1028
|
+
let index = fromIndex - 1,
|
|
1029
|
+
resultIndex = -1
|
|
1030
|
+
while (++index < toIndex) {
|
|
1031
|
+
const resultItem = mapper(array[index], index, array)
|
|
1032
|
+
if (isPromise(resultItem)) {
|
|
1033
|
+
const promises = [resultItem.then(_arraySetter(result, ++resultIndex))]
|
|
1034
|
+
return _asyncSliceMapWithIndexContinued(
|
|
1035
|
+
array, toIndex, mapper, result, index, resultIndex, promises)
|
|
1036
|
+
}
|
|
1037
|
+
result[++resultIndex] = resultItem
|
|
1038
|
+
}
|
|
1039
|
+
return result
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
const _asyncArrayFilterWithIndex2 = async function (
|
|
1043
|
+
array, predicate, result, index, shouldIncludeFirstItemPromise,
|
|
1044
|
+
) {
|
|
1045
|
+
const arrayLength = array.length,
|
|
1046
|
+
resultOffset = result.length + 1,
|
|
1047
|
+
[
|
|
1048
|
+
shouldIncludeFirstItem,
|
|
1049
|
+
shouldIncludeRemainingItems,
|
|
1050
|
+
] = await promiseAll([
|
|
1051
|
+
shouldIncludeFirstItemPromise,
|
|
1052
|
+
sliceMapWithIndex(array, index + 1, array.length, predicate),
|
|
1053
|
+
])
|
|
1054
|
+
let resultIndex = result.length - 1
|
|
1055
|
+
if (shouldIncludeFirstItem) {
|
|
1056
|
+
result[++resultIndex] = array[index]
|
|
1057
|
+
}
|
|
1058
|
+
while (++index < arrayLength) {
|
|
1059
|
+
if (shouldIncludeRemainingItems[index - resultOffset]) {
|
|
1060
|
+
result[++resultIndex] = array[index]
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
return result
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
const arrayFilterWithIndex2 = function (array, predicate) {
|
|
1067
|
+
const arrayLength = array.length,
|
|
1068
|
+
result = []
|
|
1069
|
+
let index = -1,
|
|
1070
|
+
resultIndex = -1
|
|
1071
|
+
while (++index < arrayLength) {
|
|
1072
|
+
const item = array[index]
|
|
1073
|
+
const shouldIncludeItem = predicate(item, index, array)
|
|
1074
|
+
if (isPromise(shouldIncludeItem)) {
|
|
1075
|
+
return _asyncArrayFilterWithIndex2(
|
|
1076
|
+
array, predicate, result, index, shouldIncludeItem)
|
|
1077
|
+
}
|
|
1078
|
+
if (shouldIncludeItem) {
|
|
1079
|
+
result[++resultIndex] = item
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
return result
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
const _asyncArrayFilterWithIndex3 = function (array, predicate, result, index) {
|
|
1086
|
+
const remainingItems = array.slice(index)
|
|
1087
|
+
const shouldIncludeItemPromises = remainingItems.map(
|
|
1088
|
+
item => predicate(item, ++index, array))
|
|
1089
|
+
return promiseAll(shouldIncludeItemPromises).then(res =>
|
|
1090
|
+
arrayExtend(result, remainingItems.filter((_, index) => res[index])))
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
const arrayFilterWithIndex3 = function (array, predicate) {
|
|
1094
|
+
const arrayLength = array.length,
|
|
1095
|
+
result = []
|
|
1096
|
+
let index = -1,
|
|
1097
|
+
resultIndex = -1
|
|
1098
|
+
while (++index < arrayLength) {
|
|
1099
|
+
const item = array[index]
|
|
1100
|
+
const shouldIncludeItem = predicate(item, index, array)
|
|
1101
|
+
if (isPromise(shouldIncludeItem)) {
|
|
1102
|
+
return _asyncArrayFilterWithIndex3(array, predicate, result, index)
|
|
1103
|
+
}
|
|
1104
|
+
if (shouldIncludeItem) {
|
|
1105
|
+
result[++resultIndex] = item
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
return result
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
const _asyncArrayFilterWithIndex30 = function (
|
|
1112
|
+
array, predicate, result, index, shouldIncludeItemPromises,
|
|
1113
|
+
) {
|
|
1114
|
+
const arrayLength = array.length,
|
|
1115
|
+
remainingItems = array.slice(index)
|
|
1116
|
+
let booleanPromisesIndex = 0
|
|
1117
|
+
while (++index < array.length) {
|
|
1118
|
+
shouldIncludeItemPromises[++booleanPromisesIndex] = predicate(
|
|
1119
|
+
array[index], index, array)
|
|
1120
|
+
}
|
|
1121
|
+
return promiseAll(shouldIncludeItemPromises).then(res =>
|
|
1122
|
+
arrayExtend(result, remainingItems.filter((_, index) => res[index])))
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
const arrayFilterWithIndex30 = function (array, predicate) {
|
|
1126
|
+
const arrayLength = array.length,
|
|
1127
|
+
result = []
|
|
1128
|
+
let index = -1,
|
|
1129
|
+
resultIndex = -1
|
|
1130
|
+
while (++index < arrayLength) {
|
|
1131
|
+
const item = array[index]
|
|
1132
|
+
const shouldIncludeItem = predicate(item, index, array)
|
|
1133
|
+
if (isPromise(shouldIncludeItem)) {
|
|
1134
|
+
return _asyncArrayFilterWithIndex30(array, predicate, result, index, [shouldIncludeItem])
|
|
1135
|
+
}
|
|
1136
|
+
if (shouldIncludeItem) {
|
|
1137
|
+
result[++resultIndex] = item
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
return result
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
const _asyncArrayFilterWithIndex31 = function (
|
|
1144
|
+
array, predicate, result, index, shouldIncludeItemPromises,
|
|
1145
|
+
) {
|
|
1146
|
+
const arrayLength = array.length
|
|
1147
|
+
let booleanPromisesIndex = 0,
|
|
1148
|
+
indexCopy = index
|
|
1149
|
+
while (++index < arrayLength) {
|
|
1150
|
+
shouldIncludeItemPromises[++booleanPromisesIndex] = predicate(
|
|
1151
|
+
array[index], index, array)
|
|
1152
|
+
}
|
|
1153
|
+
index = indexCopy - 1
|
|
1154
|
+
return promiseAll(shouldIncludeItemPromises).then(function (res) {
|
|
1155
|
+
let resultIndex = result.length - 1,
|
|
1156
|
+
resIndex = -1
|
|
1157
|
+
while (++index < arrayLength) {
|
|
1158
|
+
if (res[++resIndex]) {
|
|
1159
|
+
result[++resultIndex] = array[index]
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
return result
|
|
1163
|
+
})
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
const arrayFilterWithIndex31 = function (array, predicate) {
|
|
1167
|
+
const arrayLength = array.length,
|
|
1168
|
+
result = []
|
|
1169
|
+
let index = -1,
|
|
1170
|
+
resultIndex = -1
|
|
1171
|
+
while (++index < arrayLength) {
|
|
1172
|
+
const item = array[index]
|
|
1173
|
+
const shouldIncludeItem = predicate(item, index, array)
|
|
1174
|
+
if (isPromise(shouldIncludeItem)) {
|
|
1175
|
+
return _asyncArrayFilterWithIndex31(array, predicate, result, index, [shouldIncludeItem])
|
|
1176
|
+
}
|
|
1177
|
+
if (shouldIncludeItem) {
|
|
1178
|
+
result[++resultIndex] = item
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
return result
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
const _arrayExtendMapWithIndex = function (array, values, valuesIndex, predicate) {
|
|
1185
|
+
const valuesLength = values.length
|
|
1186
|
+
let arrayIndex = array.length - 1
|
|
1187
|
+
while (++valuesIndex < valuesLength) {
|
|
1188
|
+
array[++arrayIndex] = predicate(
|
|
1189
|
+
values[valuesIndex], valuesIndex, values)
|
|
1190
|
+
}
|
|
1191
|
+
return array
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
const _asyncArrayFilterWithIndex32 = (
|
|
1195
|
+
array, predicate, result, index, shouldIncludeItemPromises,
|
|
1196
|
+
) => promiseAll(
|
|
1197
|
+
_arrayExtendMapWithIndex(
|
|
1198
|
+
shouldIncludeItemPromises, array, index, predicate)).then(
|
|
1199
|
+
_shouldIncludeItemsResolver(array, result, index))
|
|
1200
|
+
|
|
1201
|
+
const arrayFilterWithIndex32 = function (array, predicate) {
|
|
1202
|
+
const arrayLength = array.length,
|
|
1203
|
+
result = []
|
|
1204
|
+
let index = -1,
|
|
1205
|
+
resultIndex = -1
|
|
1206
|
+
while (++index < arrayLength) {
|
|
1207
|
+
const item = array[index]
|
|
1208
|
+
const shouldIncludeItem = predicate(item, index, array)
|
|
1209
|
+
if (isPromise(shouldIncludeItem)) {
|
|
1210
|
+
return _asyncArrayFilterWithIndex32(
|
|
1211
|
+
array, predicate, result, index, [shouldIncludeItem])
|
|
1212
|
+
}
|
|
1213
|
+
if (shouldIncludeItem) {
|
|
1214
|
+
result[++resultIndex] = item
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
return result
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
const shouldIncludeItemsResolver = (
|
|
1221
|
+
array, result, index,
|
|
1222
|
+
) => function resolvingShouldIncludeItems(shouldIncludeItems) {
|
|
1223
|
+
const arrayLength = array.length
|
|
1224
|
+
let resultIndex = result.length - 1,
|
|
1225
|
+
shouldIncludeItemsIndex = -1
|
|
1226
|
+
while (++index < arrayLength) {
|
|
1227
|
+
if (shouldIncludeItems[++shouldIncludeItemsIndex]) {
|
|
1228
|
+
result[++resultIndex] = array[index]
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
return result
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
const arrayExtendMapWithIndex = function (
|
|
1235
|
+
array, values, valuesMapper, valuesIndex,
|
|
1236
|
+
) {
|
|
1237
|
+
const valuesLength = values.length
|
|
1238
|
+
let arrayIndex = array.length - 1
|
|
1239
|
+
while (++valuesIndex < valuesLength) {
|
|
1240
|
+
array[++arrayIndex] = valuesMapper(
|
|
1241
|
+
values[valuesIndex], valuesIndex, values)
|
|
1242
|
+
}
|
|
1243
|
+
return array
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
const arrayFilterWithIndex33 = function (array, predicate) {
|
|
1247
|
+
const arrayLength = array.length,
|
|
1248
|
+
result = []
|
|
1249
|
+
let index = -1,
|
|
1250
|
+
resultIndex = -1
|
|
1251
|
+
while (++index < arrayLength) {
|
|
1252
|
+
const item = array[index]
|
|
1253
|
+
const shouldIncludeItem = predicate(item, index, array)
|
|
1254
|
+
if (isPromise(shouldIncludeItem)) {
|
|
1255
|
+
return promiseAll(
|
|
1256
|
+
arrayExtendMapWithIndex(
|
|
1257
|
+
[shouldIncludeItem], array, predicate, index)).then(
|
|
1258
|
+
shouldIncludeItemsResolver(array, result, index - 1))
|
|
1259
|
+
}
|
|
1260
|
+
if (shouldIncludeItem) {
|
|
1261
|
+
result[++resultIndex] = item
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
return result
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
{
|
|
1268
|
+
const array = [1, 2, 3, 4, 5]
|
|
1269
|
+
|
|
1270
|
+
const isOdd = number => number % 2 == 1
|
|
1271
|
+
|
|
1272
|
+
const asyncIsOdd = async number => number % 2 == 1
|
|
1273
|
+
|
|
1274
|
+
// console.log(arrayFilterWithIndex0(array, isOdd))
|
|
1275
|
+
// console.log(arrayFilterWithIndex1(array, isOdd))
|
|
1276
|
+
// console.log(arrayFilterWithIndex2(array, isOdd))
|
|
1277
|
+
// console.log(arrayFilterWithIndex3(array, isOdd))
|
|
1278
|
+
// console.log(arrayFilterWithIndex30(array, isOdd))
|
|
1279
|
+
// console.log(arrayFilterWithIndex31(array, isOdd))
|
|
1280
|
+
// console.log(arrayFilterWithIndex32(array, isOdd))
|
|
1281
|
+
// console.log(arrayFilterWithIndex33(array, isOdd))
|
|
1282
|
+
// arrayFilterWithIndex0(array, asyncIsOdd).then(console.log)
|
|
1283
|
+
// arrayFilterWithIndex1(array, asyncIsOdd).then(console.log)
|
|
1284
|
+
// arrayFilterWithIndex2(array, asyncIsOdd).then(console.log)
|
|
1285
|
+
// arrayFilterWithIndex3(array, asyncIsOdd).then(console.log)
|
|
1286
|
+
// arrayFilterWithIndex30(array, asyncIsOdd).then(console.log)
|
|
1287
|
+
// arrayFilterWithIndex31(array, asyncIsOdd).then(console.log)
|
|
1288
|
+
// arrayFilterWithIndex32(array, asyncIsOdd).then(console.log)
|
|
1289
|
+
// arrayFilterWithIndex33(array, asyncIsOdd).then(console.log)
|
|
1290
|
+
|
|
1291
|
+
// timeInLoop('arrayFilterWithIndex0', 1e6, () => arrayFilterWithIndex0(array, isOdd))
|
|
1292
|
+
|
|
1293
|
+
// timeInLoop('arrayFilterWithIndex1', 1e6, () => arrayFilterWithIndex1(array, isOdd))
|
|
1294
|
+
|
|
1295
|
+
// timeInLoop('arrayFilterWithIndex2', 1e6, () => arrayFilterWithIndex2(array, isOdd))
|
|
1296
|
+
|
|
1297
|
+
// timeInLoop('arrayFilterWithIndex3', 1e6, () => arrayFilterWithIndex3(array, isOdd))
|
|
1298
|
+
|
|
1299
|
+
// timeInLoop('arrayFilterWithIndex30', 1e6, () => arrayFilterWithIndex30(array, isOdd))
|
|
1300
|
+
|
|
1301
|
+
// timeInLoop('arrayFilterWithIndex31', 1e6, () => arrayFilterWithIndex31(array, isOdd))
|
|
1302
|
+
|
|
1303
|
+
// timeInLoop('arrayFilterWithIndex32', 1e6, () => arrayFilterWithIndex32(array, isOdd))
|
|
1304
|
+
|
|
1305
|
+
// timeInLoop('arrayFilterWithIndex33', 1e6, () => arrayFilterWithIndex33(array, isOdd))
|
|
1306
|
+
|
|
1307
|
+
// timeInLoop.async('arrayFilterWithIndex0 - async', 1e5, () => arrayFilterWithIndex0(array, asyncIsOdd))
|
|
1308
|
+
|
|
1309
|
+
// timeInLoop.async('arrayFilterWithIndex1 - async', 1e5, () => arrayFilterWithIndex1(array, asyncIsOdd))
|
|
1310
|
+
|
|
1311
|
+
// timeInLoop.async('arrayFilterWithIndex2 - async', 1e5, () => arrayFilterWithIndex2(array, asyncIsOdd))
|
|
1312
|
+
|
|
1313
|
+
// timeInLoop.async('arrayFilterWithIndex3 - async', 1e5, () => arrayFilterWithIndex3(array, asyncIsOdd))
|
|
1314
|
+
|
|
1315
|
+
// timeInLoop.async('arrayFilterWithIndex30 - async', 1e5, () => arrayFilterWithIndex30(array, asyncIsOdd))
|
|
1316
|
+
|
|
1317
|
+
// timeInLoop.async('arrayFilterWithIndex31 - async', 1e5, () => arrayFilterWithIndex31(array, asyncIsOdd))
|
|
1318
|
+
|
|
1319
|
+
// timeInLoop.async('arrayFilterWithIndex32 - async', 1e5, () => arrayFilterWithIndex32(array, asyncIsOdd))
|
|
1320
|
+
|
|
1321
|
+
// timeInLoop.async('arrayFilterWithIndex33 - async', 1e5, () => arrayFilterWithIndex33(array, asyncIsOdd))
|
|
1322
|
+
}
|