rubico 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/Transducer.js +28 -0
- package/_internal/genericTransform.js +30 -28
- package/_internal/reducerTryCatch.js +55 -0
- package/dist/Transducer.es.js +28 -1
- package/dist/Transducer.es.min.js +2 -2
- package/dist/Transducer.js +28 -1
- package/dist/Transducer.min.js +2 -2
- package/dist/Transducer.mjs +28 -1
- package/dist/__.es.js +1 -1
- package/dist/__.es.min.js +1 -1
- package/dist/__.js +1 -1
- package/dist/__.min.js +1 -1
- package/dist/__.mjs +1 -1
- package/dist/all.es.js +1 -1
- package/dist/all.es.min.js +1 -1
- package/dist/all.js +1 -1
- package/dist/all.min.js +1 -1
- package/dist/all.mjs +1 -1
- package/dist/always.es.js +1 -1
- package/dist/always.es.min.js +1 -1
- package/dist/always.js +1 -1
- package/dist/always.min.js +1 -1
- package/dist/always.mjs +1 -1
- package/dist/and.es.js +1 -1
- package/dist/and.es.min.js +1 -1
- package/dist/and.js +1 -1
- package/dist/and.min.js +1 -1
- package/dist/and.mjs +1 -1
- package/dist/assign.es.js +1 -1
- package/dist/assign.es.min.js +1 -1
- package/dist/assign.js +1 -1
- package/dist/assign.min.js +1 -1
- package/dist/assign.mjs +1 -1
- package/dist/compose.es.js +1 -1
- package/dist/compose.es.min.js +1 -1
- package/dist/compose.js +1 -1
- package/dist/compose.min.js +1 -1
- package/dist/compose.mjs +1 -1
- package/dist/curry.es.js +1 -1
- package/dist/curry.es.min.js +1 -1
- package/dist/curry.js +1 -1
- package/dist/curry.min.js +1 -1
- package/dist/curry.mjs +1 -1
- package/dist/eq.es.js +1 -1
- package/dist/eq.es.min.js +1 -1
- package/dist/eq.js +1 -1
- package/dist/eq.min.js +1 -1
- package/dist/eq.mjs +1 -1
- package/dist/every.es.js +1 -1
- package/dist/every.es.min.js +1 -1
- package/dist/every.js +1 -1
- package/dist/every.min.js +1 -1
- package/dist/every.mjs +1 -1
- package/dist/filter.es.js +1 -1
- package/dist/filter.es.min.js +1 -1
- package/dist/filter.js +1 -1
- package/dist/filter.min.js +1 -1
- package/dist/filter.mjs +1 -1
- package/dist/flatMap.es.js +1 -1
- package/dist/flatMap.es.min.js +1 -1
- package/dist/flatMap.js +1 -1
- package/dist/flatMap.min.js +1 -1
- package/dist/flatMap.mjs +1 -1
- package/dist/forEach.es.js +1 -1
- package/dist/forEach.es.min.js +1 -1
- package/dist/forEach.js +1 -1
- package/dist/forEach.min.js +1 -1
- package/dist/forEach.mjs +1 -1
- package/dist/get.es.js +1 -1
- package/dist/get.es.min.js +1 -1
- package/dist/get.js +1 -1
- package/dist/get.min.js +1 -1
- package/dist/get.mjs +1 -1
- package/dist/gt.es.js +1 -1
- package/dist/gt.es.min.js +1 -1
- package/dist/gt.js +1 -1
- package/dist/gt.min.js +1 -1
- package/dist/gt.mjs +1 -1
- package/dist/gte.es.js +1 -1
- package/dist/gte.es.min.js +1 -1
- package/dist/gte.js +1 -1
- package/dist/gte.min.js +1 -1
- package/dist/gte.mjs +1 -1
- package/dist/lt.es.js +1 -1
- package/dist/lt.es.min.js +1 -1
- package/dist/lt.js +1 -1
- package/dist/lt.min.js +1 -1
- package/dist/lt.mjs +1 -1
- package/dist/lte.es.js +1 -1
- package/dist/lte.es.min.js +1 -1
- package/dist/lte.js +1 -1
- package/dist/lte.min.js +1 -1
- package/dist/lte.mjs +1 -1
- package/dist/map.es.js +1 -1
- package/dist/map.es.min.js +1 -1
- package/dist/map.js +1 -1
- package/dist/map.min.js +1 -1
- package/dist/map.mjs +1 -1
- package/dist/not.es.js +1 -1
- package/dist/not.es.min.js +1 -1
- package/dist/not.js +1 -1
- package/dist/not.min.js +1 -1
- package/dist/not.mjs +1 -1
- package/dist/omit.es.js +1 -1
- package/dist/omit.es.min.js +1 -1
- package/dist/omit.js +1 -1
- package/dist/omit.min.js +1 -1
- package/dist/omit.mjs +1 -1
- package/dist/or.es.js +1 -1
- package/dist/or.es.min.js +1 -1
- package/dist/or.js +1 -1
- package/dist/or.min.js +1 -1
- package/dist/or.mjs +1 -1
- package/dist/pick.es.js +1 -1
- package/dist/pick.es.min.js +1 -1
- package/dist/pick.js +1 -1
- package/dist/pick.min.js +1 -1
- package/dist/pick.mjs +1 -1
- package/dist/pipe.es.js +1 -1
- package/dist/pipe.es.min.js +1 -1
- package/dist/pipe.js +1 -1
- package/dist/pipe.min.js +1 -1
- package/dist/pipe.mjs +1 -1
- package/dist/reduce.es.js +1 -1
- package/dist/reduce.es.min.js +1 -1
- package/dist/reduce.js +1 -1
- package/dist/reduce.min.js +1 -1
- package/dist/reduce.mjs +1 -1
- package/dist/rubico.es.js +57 -46
- package/dist/rubico.es.min.js +2 -2
- package/dist/rubico.global.js +57 -46
- package/dist/rubico.global.min.js +2 -2
- package/dist/rubico.js +57 -46
- package/dist/rubico.min.js +2 -2
- package/dist/rubico.mjs +57 -46
- package/dist/set.es.js +1 -1
- package/dist/set.es.min.js +1 -1
- package/dist/set.js +1 -1
- package/dist/set.min.js +1 -1
- package/dist/set.mjs +1 -1
- package/dist/some.es.js +1 -1
- package/dist/some.es.min.js +1 -1
- package/dist/some.js +1 -1
- package/dist/some.min.js +1 -1
- package/dist/some.mjs +1 -1
- package/dist/switchCase.es.js +1 -1
- package/dist/switchCase.es.min.js +1 -1
- package/dist/switchCase.js +1 -1
- package/dist/switchCase.min.js +1 -1
- package/dist/switchCase.mjs +1 -1
- package/dist/tap.es.js +32 -2
- package/dist/tap.es.min.js +2 -2
- package/dist/tap.js +32 -2
- package/dist/tap.min.js +2 -2
- package/dist/tap.mjs +32 -2
- package/dist/thunkify.es.js +1 -1
- package/dist/thunkify.es.min.js +1 -1
- package/dist/thunkify.js +1 -1
- package/dist/thunkify.min.js +1 -1
- package/dist/thunkify.mjs +1 -1
- package/dist/transform.es.js +26 -24
- package/dist/transform.es.min.js +2 -2
- package/dist/transform.js +26 -24
- package/dist/transform.min.js +2 -2
- package/dist/transform.mjs +26 -24
- package/dist/tryCatch.es.js +1 -1
- package/dist/tryCatch.es.min.js +1 -1
- package/dist/tryCatch.js +1 -1
- package/dist/tryCatch.min.js +1 -1
- package/dist/tryCatch.mjs +1 -1
- package/dist/x/append.es.js +1 -1
- package/dist/x/append.es.min.js +1 -1
- package/dist/x/append.js +1 -1
- package/dist/x/append.min.js +1 -1
- package/dist/x/append.mjs +1 -1
- package/dist/x/callProp.es.js +1 -1
- package/dist/x/callProp.es.min.js +1 -1
- package/dist/x/callProp.js +1 -1
- package/dist/x/callProp.min.js +1 -1
- package/dist/x/callProp.mjs +1 -1
- package/dist/x/defaultsDeep.es.js +1 -1
- package/dist/x/defaultsDeep.es.min.js +1 -1
- package/dist/x/defaultsDeep.js +1 -1
- package/dist/x/defaultsDeep.min.js +1 -1
- package/dist/x/defaultsDeep.mjs +1 -1
- package/dist/x/differenceWith.es.js +1 -1
- package/dist/x/differenceWith.es.min.js +1 -1
- package/dist/x/differenceWith.js +1 -1
- package/dist/x/differenceWith.min.js +1 -1
- package/dist/x/differenceWith.mjs +1 -1
- package/dist/x/filterOut.es.js +1 -1
- package/dist/x/filterOut.es.min.js +1 -1
- package/dist/x/filterOut.js +1 -1
- package/dist/x/filterOut.min.js +1 -1
- package/dist/x/filterOut.mjs +1 -1
- package/dist/x/find.es.js +1 -1
- package/dist/x/find.es.min.js +1 -1
- package/dist/x/find.js +1 -1
- package/dist/x/find.min.js +1 -1
- package/dist/x/find.mjs +1 -1
- package/dist/x/findIndex.es.js +1 -1
- package/dist/x/findIndex.es.min.js +1 -1
- package/dist/x/findIndex.js +1 -1
- package/dist/x/findIndex.min.js +1 -1
- package/dist/x/findIndex.mjs +1 -1
- package/dist/x/first.es.js +1 -1
- package/dist/x/first.es.min.js +1 -1
- package/dist/x/first.js +1 -1
- package/dist/x/first.min.js +1 -1
- package/dist/x/first.mjs +1 -1
- package/dist/x/flatten.es.js +1 -1
- package/dist/x/flatten.es.min.js +1 -1
- package/dist/x/flatten.js +1 -1
- package/dist/x/flatten.min.js +1 -1
- package/dist/x/flatten.mjs +1 -1
- package/dist/x/groupBy.es.js +1 -1
- package/dist/x/groupBy.es.min.js +1 -1
- package/dist/x/groupBy.js +1 -1
- package/dist/x/groupBy.min.js +1 -1
- package/dist/x/groupBy.mjs +1 -1
- package/dist/x/has.es.js +1 -1
- package/dist/x/has.es.min.js +1 -1
- package/dist/x/has.js +1 -1
- package/dist/x/has.min.js +1 -1
- package/dist/x/has.mjs +1 -1
- package/dist/x/identity.es.js +1 -1
- package/dist/x/identity.es.min.js +1 -1
- package/dist/x/identity.js +1 -1
- package/dist/x/identity.min.js +1 -1
- package/dist/x/identity.mjs +1 -1
- package/dist/x/includes.es.js +1 -1
- package/dist/x/includes.es.min.js +1 -1
- package/dist/x/includes.js +1 -1
- package/dist/x/includes.min.js +1 -1
- package/dist/x/includes.mjs +1 -1
- package/dist/x/isDeepEqual.es.js +1 -1
- package/dist/x/isDeepEqual.es.min.js +1 -1
- package/dist/x/isDeepEqual.js +1 -1
- package/dist/x/isDeepEqual.min.js +1 -1
- package/dist/x/isDeepEqual.mjs +1 -1
- package/dist/x/isEmpty.es.js +1 -1
- package/dist/x/isEmpty.es.min.js +1 -1
- package/dist/x/isEmpty.js +1 -1
- package/dist/x/isEmpty.min.js +1 -1
- package/dist/x/isEmpty.mjs +1 -1
- package/dist/x/isEqual.es.js +1 -1
- package/dist/x/isEqual.es.min.js +1 -1
- package/dist/x/isEqual.js +1 -1
- package/dist/x/isEqual.min.js +1 -1
- package/dist/x/isEqual.mjs +1 -1
- package/dist/x/isFunction.es.js +1 -1
- package/dist/x/isFunction.es.min.js +1 -1
- package/dist/x/isFunction.js +1 -1
- package/dist/x/isFunction.min.js +1 -1
- package/dist/x/isFunction.mjs +1 -1
- package/dist/x/isIn.es.js +1 -1
- package/dist/x/isIn.es.min.js +1 -1
- package/dist/x/isIn.js +1 -1
- package/dist/x/isIn.min.js +1 -1
- package/dist/x/isIn.mjs +1 -1
- package/dist/x/isObject.es.js +1 -1
- package/dist/x/isObject.es.min.js +1 -1
- package/dist/x/isObject.js +1 -1
- package/dist/x/isObject.min.js +1 -1
- package/dist/x/isObject.mjs +1 -1
- package/dist/x/isString.es.js +1 -1
- package/dist/x/isString.es.min.js +1 -1
- package/dist/x/isString.js +1 -1
- package/dist/x/isString.min.js +1 -1
- package/dist/x/isString.mjs +1 -1
- package/dist/x/keys.es.js +1 -1
- package/dist/x/keys.es.min.js +1 -1
- package/dist/x/keys.js +1 -1
- package/dist/x/keys.min.js +1 -1
- package/dist/x/keys.mjs +1 -1
- package/dist/x/last.es.js +1 -1
- package/dist/x/last.es.min.js +1 -1
- package/dist/x/last.js +1 -1
- package/dist/x/last.min.js +1 -1
- package/dist/x/last.mjs +1 -1
- package/dist/x/maxBy.es.js +1 -1
- package/dist/x/maxBy.es.min.js +1 -1
- package/dist/x/maxBy.js +1 -1
- package/dist/x/maxBy.min.js +1 -1
- package/dist/x/maxBy.mjs +1 -1
- package/dist/x/noop.es.js +1 -1
- package/dist/x/noop.es.min.js +1 -1
- package/dist/x/noop.js +1 -1
- package/dist/x/noop.min.js +1 -1
- package/dist/x/noop.mjs +1 -1
- package/dist/x/pluck.es.js +1 -1
- package/dist/x/pluck.es.min.js +1 -1
- package/dist/x/pluck.js +1 -1
- package/dist/x/pluck.min.js +1 -1
- package/dist/x/pluck.mjs +1 -1
- package/dist/x/prepend.es.js +1 -1
- package/dist/x/prepend.es.min.js +1 -1
- package/dist/x/prepend.js +1 -1
- package/dist/x/prepend.min.js +1 -1
- package/dist/x/prepend.mjs +1 -1
- package/dist/x/size.es.js +1 -1
- package/dist/x/size.es.min.js +1 -1
- package/dist/x/size.js +1 -1
- package/dist/x/size.min.js +1 -1
- package/dist/x/size.mjs +1 -1
- package/dist/x/trace.es.js +32 -2
- package/dist/x/trace.es.min.js +2 -2
- package/dist/x/trace.js +32 -2
- package/dist/x/trace.min.js +2 -2
- package/dist/x/trace.mjs +32 -2
- package/dist/x/unionWith.es.js +1 -1
- package/dist/x/unionWith.es.min.js +1 -1
- package/dist/x/unionWith.js +1 -1
- package/dist/x/unionWith.min.js +1 -1
- package/dist/x/unionWith.mjs +1 -1
- package/dist/x/uniq.es.js +1 -1
- package/dist/x/uniq.es.min.js +1 -1
- package/dist/x/uniq.js +1 -1
- package/dist/x/uniq.min.js +1 -1
- package/dist/x/uniq.mjs +1 -1
- package/dist/x/unless.es.js +1 -1
- package/dist/x/unless.es.min.js +1 -1
- package/dist/x/unless.js +1 -1
- package/dist/x/unless.min.js +1 -1
- package/dist/x/unless.mjs +1 -1
- package/dist/x/values.es.js +1 -1
- package/dist/x/values.es.min.js +1 -1
- package/dist/x/values.js +1 -1
- package/dist/x/values.min.js +1 -1
- package/dist/x/values.mjs +1 -1
- package/dist/x/when.es.js +1 -1
- package/dist/x/when.es.min.js +1 -1
- package/dist/x/when.js +1 -1
- package/dist/x/when.min.js +1 -1
- package/dist/x/when.mjs +1 -1
- package/es.js +57 -46
- package/index.js +57 -46
- package/package.json +43 -2
- package/tap.js +15 -4
- package/.eslintignore +0 -5
- package/.eslintrc.js +0 -330
- package/.github/workflows/nodejs.yml +0 -27
- package/.vscode/launch.json +0 -25
- package/AggregateReducer.test.js +0 -82
- package/CHANGELOG.md +0 -310
- package/CNAME +0 -1
- package/CODE_OF_CONDUCT.md +0 -128
- package/CONTRIBUTING.md +0 -4
- package/Transducer.test.js +0 -117
- package/_config.yml +0 -1
- package/_internal/improvedGenericTransform.js +0 -93
- package/archive/FlatMappingIterator-2020-09-28.js +0 -68
- package/archive/_Promise-2023-05-29.js +0 -93
- package/archive/arrayMap2-2023-05-29.js +0 -73
- package/archive/benchmarks-v1.9.7/all.js +0 -34
- package/archive/benchmarks-v1.9.7/and.js +0 -24
- package/archive/benchmarks-v1.9.7/any.js +0 -32
- package/archive/benchmarks-v1.9.7/assign.js +0 -174
- package/archive/benchmarks-v1.9.7/curry.js +0 -55
- package/archive/benchmarks-v1.9.7/eq.js +0 -25
- package/archive/benchmarks-v1.9.7/filter.js +0 -1322
- package/archive/benchmarks-v1.9.7/flatMap.js +0 -48
- package/archive/benchmarks-v1.9.7/forEach.js +0 -33
- package/archive/benchmarks-v1.9.7/fork.js +0 -123
- package/archive/benchmarks-v1.9.7/get.js +0 -44
- package/archive/benchmarks-v1.9.7/gt.js +0 -25
- package/archive/benchmarks-v1.9.7/gte.js +0 -25
- package/archive/benchmarks-v1.9.7/integration.js +0 -88
- package/archive/benchmarks-v1.9.7/lt.js +0 -25
- package/archive/benchmarks-v1.9.7/lte.js +0 -25
- package/archive/benchmarks-v1.9.7/map.js +0 -892
- package/archive/benchmarks-v1.9.7/misc.js +0 -470
- package/archive/benchmarks-v1.9.7/omit.js +0 -28
- package/archive/benchmarks-v1.9.7/or.js +0 -51
- package/archive/benchmarks-v1.9.7/pick.js +0 -24
- package/archive/benchmarks-v1.9.7/pipe.js +0 -152
- package/archive/benchmarks-v1.9.7/reduce.js +0 -739
- package/archive/benchmarks-v1.9.7/switchCase.js +0 -256
- package/archive/benchmarks-v1.9.7/tap.js +0 -90
- package/archive/benchmarks-v1.9.7/transform.js +0 -218
- package/archive/benchmarks-v1.9.7/tryCatch.js +0 -108
- package/archive/curry.js +0 -13
- package/archive/examples-v1.6.11/browserModule.html +0 -31
- package/archive/examples-v1.6.11/browserScript.html +0 -32
- package/archive/examples-v1.6.11/coolTransformToConsole.js +0 -1
- package/archive/examples-v1.6.11/denoLargeGasMap.js +0 -85
- package/archive/examples-v1.6.11/denoServer.js +0 -9
- package/archive/examples-v1.6.11/denoServerWithMiddleware.js +0 -55
- package/archive/examples-v1.6.11/logTodosRange.js +0 -21
- package/archive/examples-v1.6.11/makeARequest.html +0 -46
- package/archive/examples-v1.6.11/nodeComplexTransformation.js +0 -106
- package/archive/examples-v1.6.11/nodeConditionallyExtractIDs.js +0 -50
- package/archive/examples-v1.6.11/nodeFloatingPoint.js +0 -55
- package/archive/examples-v1.6.11/nodeGetAllJiraBoards.js +0 -45
- package/archive/examples-v1.6.11/nodeGetSocketIOClientsTotalCount.js +0 -34
- package/archive/examples-v1.6.11/nodeKafkaConsumer.js +0 -63
- package/archive/examples-v1.6.11/nodeMakeMultipleRequests.js +0 -55
- package/archive/examples-v1.6.11/nodeOnRecordAddTask.js +0 -34
- package/archive/examples-v1.6.11/nodePostRequestWithAuth.js +0 -36
- package/archive/examples-v1.6.11/nodeSpeedbackMatchmakingAlgorithm.js +0 -96
- package/archive/examples-v1.6.11/nodeTireData.js +0 -36
- package/archive/examples-v1.6.11/nodeTripleMap.js +0 -85
- package/archive/examples-v1.6.11/squaredOdds.ts +0 -16
- package/archive/examples-v1.6.11/transducerMaxBuyer.js +0 -67
- package/archive/examples-v1.6.11/transformLogTodosRange.js +0 -31
- package/archive/examples-v1.6.11/transformStreamRandomInts.js +0 -19
- package/archive/genericReduceConcurrent.js +0 -277
- package/archive/index.v0.2.9.js +0 -1685
- package/archive/objectValuesGenerator.js +0 -13
- package/archive/test.v0.2.9.js +0 -2334
- package/bench +0 -65
- package/benchmark-output/v1.9.7 +0 -268
- package/benchmarks/all.async.js +0 -43
- package/benchmarks/all.js +0 -43
- package/benchmarks/always.js +0 -15
- package/benchmarks/and.async.js +0 -25
- package/benchmarks/and.js +0 -25
- package/benchmarks/assign.async.js +0 -27
- package/benchmarks/assign.js +0 -27
- package/benchmarks/curry.js +0 -35
- package/benchmarks/eq.async.js +0 -23
- package/benchmarks/eq.js +0 -23
- package/benchmarks/every.async.js +0 -19
- package/benchmarks/every.js +0 -19
- package/benchmarks/filter.async.js +0 -32
- package/benchmarks/filter.js +0 -38
- package/benchmarks/flatMap.async.js +0 -26
- package/benchmarks/flatMap.js +0 -38
- package/benchmarks/get.async.js +0 -19
- package/benchmarks/get.js +0 -39
- package/benchmarks/gt.async.js +0 -23
- package/benchmarks/gt.js +0 -23
- package/benchmarks/gte.async.js +0 -23
- package/benchmarks/gte.js +0 -23
- package/benchmarks/lt.async.js +0 -23
- package/benchmarks/lt.js +0 -23
- package/benchmarks/lte.async.js +0 -23
- package/benchmarks/lte.js +0 -23
- package/benchmarks/map.async.js +0 -43
- package/benchmarks/map.js +0 -40
- package/benchmarks/misc/Promise.js +0 -26
- package/benchmarks/misc/isPromise.js +0 -30
- package/benchmarks/misc/promiseAll.js +0 -36
- package/benchmarks/not.js +0 -23
- package/benchmarks/omit.js +0 -38
- package/benchmarks/or.async.js +0 -25
- package/benchmarks/or.js +0 -25
- package/benchmarks/pick.js +0 -38
- package/benchmarks/pipe.async.js +0 -47
- package/benchmarks/pipe.js +0 -47
- package/benchmarks/reduce.async.js +0 -32
- package/benchmarks/reduce.js +0 -38
- package/benchmarks/set.async.js +0 -19
- package/benchmarks/set.js +0 -41
- package/benchmarks/some.async.js +0 -19
- package/benchmarks/some.js +0 -19
- package/benchmarks/switchCase.async.js +0 -27
- package/benchmarks/switchCase.js +0 -55
- package/benchmarks/tap.js +0 -15
- package/benchmarks/thunkify.js +0 -15
- package/benchmarks/transform.async.js +0 -27
- package/benchmarks/transform.js +0 -40
- package/benchmarks/tryCatch.async.js +0 -25
- package/benchmarks/tryCatch.js +0 -32
- package/build +0 -472
- package/dist-test.js +0 -37
- package/examples/type-to-search-wiki/README.md +0 -19
- package/examples/type-to-search-wiki/package.json +0 -13
- package/examples/type-to-search-wiki/src/app.js +0 -46
- package/examples/type-to-search-wiki/src/index.html +0 -18
- package/import-test.html +0 -73
- package/memory-usage/reduce.js +0 -40
- package/monad/AsyncPool.js +0 -0
- package/monad/BrokenPromise.js +0 -63
- package/monad/BrokenPromise.test.js +0 -22
- package/monad/Cancellable.js +0 -84
- package/monad/Cancellable.memoryUsage.js +0 -60
- package/monad/Cancellable.test.js +0 -20
- package/monad/Function.js +0 -0
- package/monad/Instance.benchmark.js +0 -378
- package/monad/Instance.js +0 -351
- package/monad/Instance.test.js +0 -445
- package/monad/Mux.benchmark.js +0 -29
- package/monad/Mux.js +0 -589
- package/monad/Mux.test.js +0 -512
- package/monad/PossiblePromise.benchmark.js +0 -87
- package/monad/PossiblePromise.js +0 -144
- package/monad/PossiblePromise.test.js +0 -89
- package/monad/README.md +0 -75
- package/monad/Reducer.js +0 -0
- package/monad/Sequence.benchmark.js +0 -42
- package/monad/Sequence.js +0 -36
- package/monad/SpecScript.js +0 -0
- package/monad/Stack.js +0 -0
- package/monad/Struct.benchmark.js +0 -154
- package/monad/Struct.js +0 -249
- package/monad/Struct.test.js +0 -237
- package/rubico.js +0 -66
- package/test.js +0 -4242
- package/tmp.js +0 -1
package/monad/PossiblePromise.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/* rubico v1.5.0
|
|
2
|
-
* https://github.com/a-synchronous/rubico
|
|
3
|
-
* (c) 2019-2020 Richard Tong
|
|
4
|
-
* rubico may be freely distributed under the MIT license.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
'use strict'
|
|
8
|
-
|
|
9
|
-
const isPromise = value => value != null && typeof value.then == 'function'
|
|
10
|
-
|
|
11
|
-
const promiseAll = Promise.all.bind(Promise)
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @name PossiblePromise
|
|
15
|
-
*
|
|
16
|
-
* @synopsis
|
|
17
|
-
* new PossiblePromise(value Promise|any) -> PossiblePromise
|
|
18
|
-
*
|
|
19
|
-
* @catchphrase
|
|
20
|
-
* Possibly a Promise
|
|
21
|
-
*/
|
|
22
|
-
const PossiblePromise = function(value) {
|
|
23
|
-
this.value = value
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @name PossiblePromise.prototype.then
|
|
28
|
-
*
|
|
29
|
-
* @synopsis
|
|
30
|
-
* new PossiblePromise(value Promise|any).then(func function) -> Promise|any
|
|
31
|
-
*
|
|
32
|
-
* @catchphrase
|
|
33
|
-
* .then if internal Promise, else call
|
|
34
|
-
*/
|
|
35
|
-
PossiblePromise.prototype.then = function(func) {
|
|
36
|
-
const value = this.value
|
|
37
|
-
return isPromise(value) ? value.then(func) : func(value)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @name PossiblePromise.then
|
|
42
|
-
*
|
|
43
|
-
* @synopsis
|
|
44
|
-
* PossiblePromise.then(value Promise|any, func function) -> Promise|any
|
|
45
|
-
*
|
|
46
|
-
* @catchphrase
|
|
47
|
-
* .then if passed a Promise, else call
|
|
48
|
-
*/
|
|
49
|
-
PossiblePromise.then = (value, func) => (
|
|
50
|
-
isPromise(value) ? value.then(func) : func(value))
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @name PossiblePromise.catch
|
|
54
|
-
*
|
|
55
|
-
* @synopsis
|
|
56
|
-
* PossiblePromise.catch(
|
|
57
|
-
* value Promise|any,
|
|
58
|
-
* func any=>Promise|any,
|
|
59
|
-
* ) -> Promise|any
|
|
60
|
-
*
|
|
61
|
-
* @catchphrase
|
|
62
|
-
* .catch if passed a Promise, else noop
|
|
63
|
-
*/
|
|
64
|
-
PossiblePromise.catch = (value, func) => (
|
|
65
|
-
isPromise(value) ? value.catch(func) : value)
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @name SyncThenable
|
|
69
|
-
*
|
|
70
|
-
* @synopsis
|
|
71
|
-
* new SyncThenable(value any) -> SyncThenable
|
|
72
|
-
*
|
|
73
|
-
* @catchphrase
|
|
74
|
-
* A synchronous Promise-like structure
|
|
75
|
-
*/
|
|
76
|
-
const SyncThenable = function(value) { this.value = value }
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @name SyncThenable.prototype.then
|
|
80
|
-
*
|
|
81
|
-
* @synopsis
|
|
82
|
-
* new SyncThenable(value any).then(func function) -> any
|
|
83
|
-
*
|
|
84
|
-
* @catchphrase
|
|
85
|
-
* .then as a function call
|
|
86
|
-
*/
|
|
87
|
-
SyncThenable.prototype.then = function(func) { return func(this.value) }
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @name PossiblePromise.all
|
|
91
|
-
*
|
|
92
|
-
* @synopsis
|
|
93
|
-
* PossiblePromise.all(
|
|
94
|
-
* values Array<Promise>|Array,
|
|
95
|
-
* ) -> Promise<Array>|PossiblePromise<Array>
|
|
96
|
-
*
|
|
97
|
-
* @catchphrase
|
|
98
|
-
* Always returns a thenable of an Array
|
|
99
|
-
*/
|
|
100
|
-
PossiblePromise.all = values => (values.some(isPromise)
|
|
101
|
-
? promiseAll(values)
|
|
102
|
-
: new SyncThenable(values))
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @name PossiblePromise.args
|
|
106
|
-
*
|
|
107
|
-
* @synopsis
|
|
108
|
-
* PossiblePromise.args(func function)(args ...any) -> Promise|any
|
|
109
|
-
*
|
|
110
|
-
* @catchphrase
|
|
111
|
-
* Resolves any Promises supplied as arguments to a function
|
|
112
|
-
*/
|
|
113
|
-
PossiblePromise.args = func => (...args) => (args.some(isPromise)
|
|
114
|
-
? promiseAll(args).then(res => func(...res))
|
|
115
|
-
: func(...args))
|
|
116
|
-
|
|
117
|
-
/* PossiblePromise.argsSome = func => (...args) => (args.some(isPromise)
|
|
118
|
-
? promiseAll(args).then(res => func(...res))
|
|
119
|
-
: func(...args))
|
|
120
|
-
|
|
121
|
-
PossiblePromise.argsSomeApply = func => {
|
|
122
|
-
const fApply = func.apply.bind(func)
|
|
123
|
-
return (...args) => (args.some(isPromise)
|
|
124
|
-
? promiseAll(args).then(res => fApply(null, res))
|
|
125
|
-
: fApply(null, args))
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
PossiblePromise.argumentsLoop = func => function() {
|
|
129
|
-
for (let i = 0; i < arguments.length; i++) {
|
|
130
|
-
if (isPromise(arguments[i])) {
|
|
131
|
-
return promiseAll(arguments).then(res => func(...res))
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return func.apply(null, arguments)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
PossiblePromise.argsLoop = func => (...args) => {
|
|
138
|
-
for (const arg of args) {
|
|
139
|
-
if (isPromise(arg)) return promiseAll(args).then(res => func(...res))
|
|
140
|
-
}
|
|
141
|
-
return func(...args)
|
|
142
|
-
} */
|
|
143
|
-
|
|
144
|
-
module.exports = PossiblePromise
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
const PossiblePromise = require('./PossiblePromise')
|
|
2
|
-
const assert = require('assert')
|
|
3
|
-
|
|
4
|
-
describe('PossiblePromise', () => {
|
|
5
|
-
describe('new PossiblePromise(p Promise|any) -> PossiblePromise', () => {
|
|
6
|
-
it('p nonPromise', async () => {
|
|
7
|
-
const pp = new PossiblePromise('hey')
|
|
8
|
-
assert.strictEqual(pp.constructor, PossiblePromise)
|
|
9
|
-
assert.strictEqual(pp.value, 'hey')
|
|
10
|
-
})
|
|
11
|
-
it('p Promise', async () => {
|
|
12
|
-
const pp = new PossiblePromise(Promise.resolve('hey'))
|
|
13
|
-
assert.strictEqual(pp.constructor, PossiblePromise)
|
|
14
|
-
assert(pp.value instanceof Promise)
|
|
15
|
-
})
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
describe('new PossiblePromise(p Promise|any).then(f function)', () => {
|
|
19
|
-
it('p nonPromise; calls f with p', async () => {
|
|
20
|
-
const pp = new PossiblePromise(10)
|
|
21
|
-
const f = number => number ** 2
|
|
22
|
-
assert.strictEqual(pp.then(f), 100)
|
|
23
|
-
})
|
|
24
|
-
it('p Promise; supplies f to p.then', async () => {
|
|
25
|
-
const pp = new PossiblePromise(Promise.resolve(10))
|
|
26
|
-
assert(pp.then(number => number ** 2) instanceof Promise)
|
|
27
|
-
assert.strictEqual(await pp.then(number => number ** 2), 100)
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
describe('PossiblePromise.then(p Promise|any, f function)', () => {
|
|
32
|
-
it('p nonPromise; calls f with nonPromise', async () => {
|
|
33
|
-
assert.strictEqual(PossiblePromise.then(10, number => number ** 2), 100)
|
|
34
|
-
})
|
|
35
|
-
it('p Promise, supplies f to p.then', async () => {
|
|
36
|
-
assert(PossiblePromise.then(Promise.resolve(10), number => number ** 2) instanceof Promise)
|
|
37
|
-
assert.strictEqual(
|
|
38
|
-
await PossiblePromise.then(Promise.resolve(10), number => number ** 2),
|
|
39
|
-
100,
|
|
40
|
-
)
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe('PossiblePromise.catch(p Promise|any, catcher function)', () => {
|
|
45
|
-
it('p nonPromise; noops, returns p', async () => {
|
|
46
|
-
assert.strictEqual(PossiblePromise.catch(1, console.error), 1)
|
|
47
|
-
})
|
|
48
|
-
it('p Promise; supplies catcher to p.catch', async () => {
|
|
49
|
-
const err = PossiblePromise.catch(
|
|
50
|
-
Promise.reject(new Error('hey')),
|
|
51
|
-
err => err,
|
|
52
|
-
)
|
|
53
|
-
assert.strictEqual((await err).message, 'hey')
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
describe('PossiblePromise.all(ps Array<Promise|any>) -> Promise', () => {
|
|
58
|
-
it('ps has some Promises; calls Promise.all', async () => {
|
|
59
|
-
const ps = [Promise.resolve('hey'), 'ho', 'hi']
|
|
60
|
-
assert(PossiblePromise.all(ps) instanceof Promise)
|
|
61
|
-
assert.deepEqual(await PossiblePromise.all(ps), ['hey', 'ho', 'hi'])
|
|
62
|
-
})
|
|
63
|
-
it('ps has no Promises; returns PossiblePromise', async () => {
|
|
64
|
-
const ps = ['hey', 'ho', 'hi']
|
|
65
|
-
assert(typeof PossiblePromise.all(ps).then === 'function')
|
|
66
|
-
assert.deepEqual(await PossiblePromise.all(ps), ps)
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
describe('PossiblePromise.args(f function)', () => {
|
|
71
|
-
it('resolves any Promises passed as arguments to f', async () => {
|
|
72
|
-
const add = (a, b) => a + b
|
|
73
|
-
assert(
|
|
74
|
-
PossiblePromise.args(add)(Promise.resolve(1), 2) instanceof Promise,
|
|
75
|
-
)
|
|
76
|
-
assert.strictEqual(
|
|
77
|
-
await PossiblePromise.args(add)(Promise.resolve(1), 2),
|
|
78
|
-
3,
|
|
79
|
-
)
|
|
80
|
-
})
|
|
81
|
-
it('behaves synchronously for no Promise arguments', async () => {
|
|
82
|
-
const add = (a, b) => a + b
|
|
83
|
-
assert.strictEqual(
|
|
84
|
-
PossiblePromise.args(add)(1, 2),
|
|
85
|
-
3,
|
|
86
|
-
)
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
})
|
package/monad/README.md
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# rubico/monad
|
|
2
|
-
|
|
3
|
-
This is a place for JavaScript monads.
|
|
4
|
-
|
|
5
|
-
Warning: this entire directory is experimental; APIs here are subject to change.
|
|
6
|
-
|
|
7
|
-
# Specification
|
|
8
|
-
|
|
9
|
-
Each rubico monad must return an object that implements `.chain`, while having some notion of `.map` and `.concat`. Similarly, while `.empty` is not strictly required, there should be some notion of an empty instance of a Monad. For example, `[]` is `empty` for Arrays. All of these methods as well as any others are free to implement; only `.chain` is required. Monads should throw TypeErrors from the constructor for invalid types of arguments. rubico Monads should generally act on objects or primitive values and not functions. A Monad that acts on a function may be better for rubico/x.
|
|
10
|
-
|
|
11
|
-
```coffeescript [specscript]
|
|
12
|
-
Monad = (args ...any)=>({
|
|
13
|
-
chain: function,
|
|
14
|
-
map: function?,
|
|
15
|
-
concat: function?,
|
|
16
|
-
empty: function?,
|
|
17
|
-
})
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Monad.prototype.chain - required
|
|
21
|
-
```coffeescript [specscript]
|
|
22
|
-
Monad(value any).chain(
|
|
23
|
-
flatMapper value=>(result Monad|any)) -> result
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Monad.prototype.map
|
|
27
|
-
```coffeescript [specscript]
|
|
28
|
-
Monad(value any).map(mapper value=>any) -> mappedMonad Monad
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Monad.prototype.concat
|
|
32
|
-
```coffeescript [specscript]
|
|
33
|
-
Monad(value any).concat(anotherMonad Monad) -> combinedMonad Monad
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Monad.prototype.empty
|
|
37
|
-
```coffeescript [specscript]
|
|
38
|
-
Monad.empty() -> emptyMonad Monad
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
# Examples
|
|
42
|
-
|
|
43
|
-
A monad's effect is activated by calling its `.chain` method with `flatMap`.
|
|
44
|
-
|
|
45
|
-
```javascript
|
|
46
|
-
const { flatMap } = require('rubico')
|
|
47
|
-
|
|
48
|
-
const Maybe = value => ({
|
|
49
|
-
chain(flatMapper) {
|
|
50
|
-
return value == null ? value : flatMapper(value)
|
|
51
|
-
},
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
flatMap(console.log)(Maybe(null))
|
|
55
|
-
|
|
56
|
-
flatMap(console.log)(Maybe('hello world')) // hello world
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Additionally, if a monad implements `.concat`, it can be transformed as a Semigroup with a transducer and `transform`.
|
|
60
|
-
|
|
61
|
-
```javascript
|
|
62
|
-
const { transform } = require('rubico')
|
|
63
|
-
|
|
64
|
-
const Max = number => ({
|
|
65
|
-
number,
|
|
66
|
-
concat(value) {
|
|
67
|
-
return Max(Math.max(
|
|
68
|
-
number, value.constructor == Max ? value.number : value))
|
|
69
|
-
},
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
transform(
|
|
73
|
-
map(Math.abs), new Max(-Infinity),
|
|
74
|
-
)([-1, -2, -3, -4, -5]) // Max { 5 }
|
|
75
|
-
```
|
package/monad/Reducer.js
DELETED
|
File without changes
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const timeInLoop = require('../x/timeInLoop')
|
|
2
|
-
|
|
3
|
-
const objectProto = Object.prototype
|
|
4
|
-
|
|
5
|
-
const nativeObjectToString = objectProto.toString
|
|
6
|
-
|
|
7
|
-
const objectToString = value => nativeObjectToString.call(value)
|
|
8
|
-
|
|
9
|
-
const symbolIterator = Symbol.iterator
|
|
10
|
-
|
|
11
|
-
const symbolAsyncIterator = Symbol.asyncIterator
|
|
12
|
-
|
|
13
|
-
const generatorFunctionTag = '[object GeneratorFunction]'
|
|
14
|
-
|
|
15
|
-
const asyncGeneratorFunctionTag = '[object AsyncGeneratorFunction]'
|
|
16
|
-
|
|
17
|
-
const isGeneratorFunction = value => {
|
|
18
|
-
const tag = objectToString(value)
|
|
19
|
-
return tag == generatorFunctionTag || tag == asyncGeneratorFunctionTag
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/*
|
|
23
|
-
* @name Sequence.isSequence
|
|
24
|
-
*
|
|
25
|
-
* @benchmark
|
|
26
|
-
* isSequence1([]): 1e+8: 103.083ms
|
|
27
|
-
* isSequence2([]): 1e+8: 102.643ms
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
const isSequence1 = value => value != null
|
|
31
|
-
&& (Boolean(value[symbolIterator])
|
|
32
|
-
|| Boolean(value[symbolAsyncIterator])
|
|
33
|
-
|| isGeneratorFunction(value))
|
|
34
|
-
|
|
35
|
-
const isSequence2 = value => value != null
|
|
36
|
-
&& (typeof value[symbolIterator] == 'function'
|
|
37
|
-
|| typeof value[symbolAsyncIterator] == 'function'
|
|
38
|
-
|| isGeneratorFunction(value))
|
|
39
|
-
|
|
40
|
-
// timeInLoop('isSequence1([])', 1e8, () => isSequence1([]))
|
|
41
|
-
|
|
42
|
-
// timeInLoop('isSequence2([])', 1e8, () => isSequence2([]))
|
package/monad/Sequence.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const symbolIterator = Symbol.iterator
|
|
4
|
-
|
|
5
|
-
const symbolAsyncIterator = Symbol.asyncIterator
|
|
6
|
-
|
|
7
|
-
const objectProto = Object.prototype
|
|
8
|
-
|
|
9
|
-
const nativeObjectToString = objectProto.toString
|
|
10
|
-
|
|
11
|
-
const objectToString = x => nativeObjectToString.call(x)
|
|
12
|
-
|
|
13
|
-
const generatorFunctionTag = '[object GeneratorFunction]'
|
|
14
|
-
|
|
15
|
-
const asyncGeneratorFunctionTag = '[object AsyncGeneratorFunction]'
|
|
16
|
-
|
|
17
|
-
const isGeneratorFunction = value => objectToString(value) == generatorFunctionTag
|
|
18
|
-
|
|
19
|
-
const isAsyncGeneratorFunction = value => objectToString(value) == asyncGeneratorFunctionTag
|
|
20
|
-
|
|
21
|
-
const isIterable = value => value != null
|
|
22
|
-
&& typeof value[symbolIterator] == 'function'
|
|
23
|
-
|
|
24
|
-
const isAsyncIterable = value => value != null
|
|
25
|
-
&& typeof value[symbolAsyncIterator] == 'function'
|
|
26
|
-
|
|
27
|
-
const Sequence = function (value) {
|
|
28
|
-
if (value == null) {
|
|
29
|
-
this.iterator = [][symbolIterator]()
|
|
30
|
-
}
|
|
31
|
-
// if (isGeneratorFunction(value)) {}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
Sequence.prototype.next = function (value) {
|
|
35
|
-
return this.iterator.next(value)
|
|
36
|
-
}
|
package/monad/SpecScript.js
DELETED
|
File without changes
|
package/monad/Stack.js
DELETED
|
File without changes
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
const timeInLoop = require('../x/timeInLoop')
|
|
2
|
-
const Struct = require('./Struct')
|
|
3
|
-
const _ = require('lodash')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @name Struct.get
|
|
7
|
-
*
|
|
8
|
-
* @benchmark
|
|
9
|
-
* structGet(arr, 0): 1e+7: 13.472ms
|
|
10
|
-
* structGetTernary(arr, 0): 1e+7: 13.414ms
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
{
|
|
14
|
-
const arr = [1, 2, 3]
|
|
15
|
-
|
|
16
|
-
const structGet = Struct.get
|
|
17
|
-
|
|
18
|
-
// timeInLoop('structGet(arr, 0)', 1e7, () => structGet(x, 0))
|
|
19
|
-
|
|
20
|
-
// const structGetTernary = Struct.get.ternary
|
|
21
|
-
|
|
22
|
-
// timeInLoop('structGetTernary(arr, 0)', 1e7, () => structGetTernary(x, 0))
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @name Struct.set
|
|
27
|
-
*
|
|
28
|
-
* @benchmark
|
|
29
|
-
* arr[5] = 6: 1e+7: 12.785ms
|
|
30
|
-
* structSet(arr, 6, 5): 1e+7: 13.989ms
|
|
31
|
-
*
|
|
32
|
-
* obj['f'] = 6: 1e+7: 12.857ms
|
|
33
|
-
* structSet(obj, 6, 'f'): 1e+7: 14.154ms
|
|
34
|
-
*
|
|
35
|
-
* set.add(6): 1e+7: 95.934ms
|
|
36
|
-
* structSet(set, 6): 1e+7: 97.659ms
|
|
37
|
-
*
|
|
38
|
-
* map.set('f', 6): 1e+7: 138.455ms
|
|
39
|
-
* structSet(map, 6, 'f'): 1e+7: 139.162ms
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
const arr = [1, 2, 3, 4, 5]
|
|
44
|
-
|
|
45
|
-
const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
|
46
|
-
|
|
47
|
-
const set = new Set([1, 2, 3, 4, 5])
|
|
48
|
-
|
|
49
|
-
const map = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
|
|
50
|
-
|
|
51
|
-
const structSet = Struct.set
|
|
52
|
-
|
|
53
|
-
// timeInLoop('arr[5] = 6', 1e7, () => { arr[5] = 6 })
|
|
54
|
-
|
|
55
|
-
// timeInLoop('structSet(arr, 6, 5)', 1e7, () => structSet(arr, 6, 5))
|
|
56
|
-
|
|
57
|
-
// timeInLoop('obj[\'f\'] = 6', 1e7, () => { obj['f'] = 6 })
|
|
58
|
-
|
|
59
|
-
// timeInLoop('structSet(obj, 6, \'f\')', 1e7, () => structSet(obj, 6, 'f'))
|
|
60
|
-
|
|
61
|
-
// timeInLoop('set.add(6)', 1e7, () => set.add(6))
|
|
62
|
-
|
|
63
|
-
// timeInLoop('structSet(set, 6)', 1e7, () => structSet(set, 6))
|
|
64
|
-
|
|
65
|
-
// timeInLoop('map.set(\'f\', 6)', 1e7, () => map.set('f', 6))
|
|
66
|
-
|
|
67
|
-
timeInLoop('structSet(map, 6, \'f\')', 1e7, () => structSet(map, 6, 'f'))
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @name Struct.size
|
|
72
|
-
*
|
|
73
|
-
* @benchmark
|
|
74
|
-
* structSize(arr): 1e+7: 14.043ms
|
|
75
|
-
* _.size(arr): 1e+7: 583.972ms
|
|
76
|
-
*
|
|
77
|
-
* structSize(obj): 1e+7: 117.314ms
|
|
78
|
-
* structSizeObjectKeys(obj): 1e+7: 213.629ms
|
|
79
|
-
* _.size(obj): 1e+7: 664.905ms
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
const structSize = Struct.size
|
|
84
|
-
|
|
85
|
-
const _size = _.size
|
|
86
|
-
|
|
87
|
-
// timeInLoop('structSize(arr)', 1e7, () => structSize(arr))
|
|
88
|
-
|
|
89
|
-
// timeInLoop('_.size(arr)', 1e7, () => _.size(arr))
|
|
90
|
-
|
|
91
|
-
const obj = { a: 1, b: 2, c: 3 }
|
|
92
|
-
|
|
93
|
-
// timeInLoop('structSize(obj)', 1e7, () => structSize(obj))
|
|
94
|
-
|
|
95
|
-
// const structSizeObjectKeys = structSize.objectKeys
|
|
96
|
-
|
|
97
|
-
// timeInLoop('structSize(obj)', 1e7, () => structSizeObjectKeys(obj))
|
|
98
|
-
|
|
99
|
-
// timeInLoop('_.size(obj)', 1e7, () => _.size(obj))
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @name Struct.copy
|
|
104
|
-
*
|
|
105
|
-
* @benchmark
|
|
106
|
-
* arr.slice(): 1e+6: 18.674ms
|
|
107
|
-
* Array.from(arr): 1e+6: 28.472ms
|
|
108
|
-
* [...arr]: 1e+6: 24.933ms
|
|
109
|
-
* Struct.copy(arr): 1e+6: 19.488ms
|
|
110
|
-
*
|
|
111
|
-
* ({ ...obj }): 1e+6: 40.274ms
|
|
112
|
-
* Object.assign({}, obj): 1e+6: 164.081ms
|
|
113
|
-
* Struct.copy(obj): 1e+6: 46.345ms
|
|
114
|
-
*
|
|
115
|
-
* new Set(set): 1e+6: 812.338ms
|
|
116
|
-
* Struct.copy(set): 1e+6: 569.508ms
|
|
117
|
-
*
|
|
118
|
-
* new Map(map): 1e+6: 303.057ms
|
|
119
|
-
* Struct.copy(map): 1e+6: 186.628ms
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
{
|
|
123
|
-
const structCopy = Struct.copy
|
|
124
|
-
|
|
125
|
-
const arr = [1, 2, 3, 4, 5]
|
|
126
|
-
|
|
127
|
-
const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
|
128
|
-
|
|
129
|
-
const set = new Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
|
|
130
|
-
|
|
131
|
-
const map = new Map([['a', 1], ['b', 2], ['c', 3]])
|
|
132
|
-
|
|
133
|
-
// timeInLoop('arr.slice()', 1e6, () => arr.slice())
|
|
134
|
-
|
|
135
|
-
// timeInLoop('Array.from(arr)', 1e6, () => Array.from(arr))
|
|
136
|
-
|
|
137
|
-
// timeInLoop('[...arr]', 1e6, () => [...arr])
|
|
138
|
-
|
|
139
|
-
// timeInLoop('Struct.copy(arr)', 1e6, () => structCopy(arr))
|
|
140
|
-
|
|
141
|
-
// timeInLoop('({ ...obj })', 1e6, () => ({ ...obj }))
|
|
142
|
-
|
|
143
|
-
// timeInLoop('Object.assign({}, obj)', 1e6, () => Object.assign({}, obj))
|
|
144
|
-
|
|
145
|
-
// timeInLoop('Struct.copy(obj)', 1e6, () => structCopy(obj))
|
|
146
|
-
|
|
147
|
-
// timeInLoop('new Set(set)', 1e6, () => new Set(set))
|
|
148
|
-
|
|
149
|
-
// timeInLoop('Struct.copy(set)', 1e6, () => structCopy(set))
|
|
150
|
-
|
|
151
|
-
// timeInLoop('new Map(map)', 1e6, () => new Map(map))
|
|
152
|
-
|
|
153
|
-
// timeInLoop('Struct.copy(map)', 1e6, () => structCopy(map))
|
|
154
|
-
}
|