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
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<title></title>
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
<script src="https://unpkg.com/rubico/index.js" crossorigin></script>
|
|
9
|
-
<script>
|
|
10
|
-
const {
|
|
11
|
-
pipe, fork, assign, tap, tryCatch, switchCase,
|
|
12
|
-
map, filter, reduce, transform,
|
|
13
|
-
any, all, and, or, not,
|
|
14
|
-
eq, gt, lt, gte, lte,
|
|
15
|
-
get, pick, omit,
|
|
16
|
-
} = rubico
|
|
17
|
-
|
|
18
|
-
const asyncNumbersGeneratedIterable = (async function*() {
|
|
19
|
-
for (let i = 0; i < 5; i++) { yield i + 1 }
|
|
20
|
-
})() // generated async iterable that yields 1 2 3 4 5
|
|
21
|
-
|
|
22
|
-
const square = x => x ** 2
|
|
23
|
-
|
|
24
|
-
console.log('squaring [1, 2, 3, 4, 5]')
|
|
25
|
-
|
|
26
|
-
transform(map(pipe([
|
|
27
|
-
square,
|
|
28
|
-
console.log,
|
|
29
|
-
])), null)(asyncNumbersGeneratedIterable) // > 1 4 9 16 25
|
|
30
|
-
</script>
|
|
31
|
-
</body>
|
|
32
|
-
</html>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// TODO
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S deno run --allow-net
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
pipe, fork, tap, map, filter, reduce, transform, get, not,
|
|
5
|
-
} from '../rubico.js'
|
|
6
|
-
|
|
7
|
-
const apiKey = "709a7d013e4fda8f3e21166c33a1a691"
|
|
8
|
-
|
|
9
|
-
const urls = [
|
|
10
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001160J/DE',
|
|
11
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/37X0000000000151/DE',
|
|
12
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/37X0000000000224/DE',
|
|
13
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001125L/DE',
|
|
14
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X0000000010849/DE',
|
|
15
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001368W/DE',
|
|
16
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X0000000011756/DE',
|
|
17
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001090E/DE',
|
|
18
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X0000000013805/DE',
|
|
19
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001262B/DE',
|
|
20
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001140P/DE',
|
|
21
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/37X000000000042Z/DE',
|
|
22
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X0000000011748/DE',
|
|
23
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/11XNERGIE------1/DE',
|
|
24
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/37X0000000000119/DE',
|
|
25
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/25X-OMVGASSTORA5/DE',
|
|
26
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/11XSWHANNOVERAG3/DE',
|
|
27
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001072G/DE',
|
|
28
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/11XSWB-BREMEN--I/DE',
|
|
29
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/37X000000000051Y/DE',
|
|
30
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001307F/DE',
|
|
31
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001310Q/DE',
|
|
32
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001127H/DE',
|
|
33
|
-
'https://cors-anywhere.herokuapp.com/https://agsi.gie.eu/api/data/21X000000001138C/DE',
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
const getData = url => fetch(url, {
|
|
37
|
-
method: 'GET',
|
|
38
|
-
headers: {
|
|
39
|
-
'x-key': apiKey,
|
|
40
|
-
'Origin': null,
|
|
41
|
-
},
|
|
42
|
-
}).then(res => res.json())
|
|
43
|
-
|
|
44
|
-
const incrementMap = (y, xi) => {
|
|
45
|
-
const [gasDate, gasVol] = xi
|
|
46
|
-
if (y.has(gasDate)) {
|
|
47
|
-
y.set(gasDate, y.get(gasDate) + gasVol)
|
|
48
|
-
} else {
|
|
49
|
-
y.set(gasDate, gasVol)
|
|
50
|
-
}
|
|
51
|
-
return y
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// url => [gas_record]
|
|
55
|
-
const toGasDateVolRecordsMap = url => pipe([
|
|
56
|
-
getData,
|
|
57
|
-
reduce(pipe([
|
|
58
|
-
map(fork([
|
|
59
|
-
get('gasDayStartedOn'),
|
|
60
|
-
pipe([get('gasInStorage'), parseFloat]),
|
|
61
|
-
])),
|
|
62
|
-
filter(pipe([get(1), not(isNaN)])),
|
|
63
|
-
])(incrementMap), new Map()),
|
|
64
|
-
tap(() => console.log('done with', url)),
|
|
65
|
-
])(url)
|
|
66
|
-
|
|
67
|
-
// mapA, mapB -> mapC
|
|
68
|
-
const combineMaps = (y, xi) => {
|
|
69
|
-
let newMap = y
|
|
70
|
-
for (const record of xi) {
|
|
71
|
-
newMap = incrementMap(newMap, record)
|
|
72
|
-
}
|
|
73
|
-
return y
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
console.log('beginning requests')
|
|
77
|
-
const now = Date.now()
|
|
78
|
-
const finalMap = await pipe([
|
|
79
|
-
map(toGasDateVolRecordsMap),
|
|
80
|
-
reduce(combineMaps, new Map()),
|
|
81
|
-
])(urls)
|
|
82
|
-
|
|
83
|
-
console.log(finalMap, 'in', Date.now() - now, 'ms')
|
|
84
|
-
|
|
85
|
-
// https://stackoverflow.com/questions/61798071/javascript-api-promise-problem-need-faster-solution
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S deno run --allow-net
|
|
2
|
-
|
|
3
|
-
import { serve } from "https://deno.land/std/http/server.ts";
|
|
4
|
-
import { map, transform } from "../rubico.js";
|
|
5
|
-
const s = serve({ port: 8001 });
|
|
6
|
-
console.log("http://localhost:8001/");
|
|
7
|
-
transform(map(req => {
|
|
8
|
-
req.respond({ body: "Hello World\n" });
|
|
9
|
-
}), null)(s);
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S deno run --allow-net
|
|
2
|
-
|
|
3
|
-
import { serve } from 'https://deno.land/std/http/server.ts'
|
|
4
|
-
import {
|
|
5
|
-
pipe, fork, assign, tap, tryCatch, switchCase,
|
|
6
|
-
map, filter, reduce, transform,
|
|
7
|
-
any, all, and, or, not,
|
|
8
|
-
eq, gt, lt, gte, lte,
|
|
9
|
-
get, pick, omit,
|
|
10
|
-
} from '../rubico.js'
|
|
11
|
-
|
|
12
|
-
const join = delim => x => x.join(delim)
|
|
13
|
-
|
|
14
|
-
const addServerTime = req => {
|
|
15
|
-
req.serverTime = (new Date()).toJSON()
|
|
16
|
-
return req
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const traceRequest = pipe([
|
|
20
|
-
fork([
|
|
21
|
-
pipe([get('serverTime'), x => '[' + x + ']']),
|
|
22
|
-
get('method'),
|
|
23
|
-
get('url'),
|
|
24
|
-
]),
|
|
25
|
-
join(' '),
|
|
26
|
-
console.log,
|
|
27
|
-
])
|
|
28
|
-
|
|
29
|
-
const respondWithHelloWorld = req => {
|
|
30
|
-
req.respond({ body: 'Hello World\n' })
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const respondWithServerTime = req => {
|
|
34
|
-
req.respond({ body: `The server time is ${req.serverTime}\n` })
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const respondWithNotFound = req => {
|
|
38
|
-
req.respond({ body: 'Not Found\n' })
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const route = switchCase([
|
|
42
|
-
eq('/', get('url')), respondWithHelloWorld,
|
|
43
|
-
eq('/time', get('url')), respondWithServerTime,
|
|
44
|
-
respondWithNotFound,
|
|
45
|
-
])
|
|
46
|
-
|
|
47
|
-
const onRequest = pipe([
|
|
48
|
-
addServerTime,
|
|
49
|
-
tap(traceRequest),
|
|
50
|
-
route,
|
|
51
|
-
])
|
|
52
|
-
|
|
53
|
-
const s = serve({ port: 8001 })
|
|
54
|
-
console.log('http://localhost:8001/')
|
|
55
|
-
transform(map(onRequest), null)(s)
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const { pipe, map } = require('rubico')
|
|
2
|
-
const fetch = require('node-fetch')
|
|
3
|
-
|
|
4
|
-
const toTodosUrl = id => 'https://jsonplaceholder.typicode.com/todos/' + id
|
|
5
|
-
|
|
6
|
-
const fetchedToJson = fetched => fetched.json()
|
|
7
|
-
|
|
8
|
-
const todoIDsRange = function* (from, to) {
|
|
9
|
-
for (let id = from; id <= to; id++) {
|
|
10
|
-
yield id
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const logTodosRange = map(pipe([
|
|
15
|
-
toTodosUrl,
|
|
16
|
-
fetch,
|
|
17
|
-
fetchedToJson,
|
|
18
|
-
console.log,
|
|
19
|
-
]))(todoIDsRange)
|
|
20
|
-
|
|
21
|
-
;[...logTodosRange(1, 100)]
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<title>makeARequest</title>
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
|
|
9
|
-
<script type="module">
|
|
10
|
-
import r, {
|
|
11
|
-
pipe, fork, assign, tap, tryCatch, switchCase,
|
|
12
|
-
map, filter, reduce, transform,
|
|
13
|
-
any, all, and, or, not,
|
|
14
|
-
eq, gt, lt, gte, lte,
|
|
15
|
-
get, pick, omit,
|
|
16
|
-
} from 'https://deno.land/x/rubico/rubico.js'
|
|
17
|
-
|
|
18
|
-
const appendToBody = (name, data) => {
|
|
19
|
-
const div = document.createElement('div')
|
|
20
|
-
div.textContent = [name, JSON.stringify(data, null, 2)].join(' ')
|
|
21
|
-
document.body.appendChild(div)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// promise chains
|
|
25
|
-
fetch('https://jsonplaceholder.typicode.com/todos/1')
|
|
26
|
-
.then(res => res.json())
|
|
27
|
-
.then(data => appendToBody('promise chains', data))
|
|
28
|
-
|
|
29
|
-
// async/await
|
|
30
|
-
void (async () => {
|
|
31
|
-
const res = await fetch('https://jsonplaceholder.typicode.com/todos/1')
|
|
32
|
-
const data = await res.json()
|
|
33
|
-
appendToBody('async/await', data)
|
|
34
|
-
})()
|
|
35
|
-
|
|
36
|
-
// rubico
|
|
37
|
-
pipe([
|
|
38
|
-
fetch.bind(window),
|
|
39
|
-
res => res.json(),
|
|
40
|
-
data => appendToBody('rubico', data)
|
|
41
|
-
])('https://jsonplaceholder.typicode.com/todos/1')
|
|
42
|
-
</script>
|
|
43
|
-
|
|
44
|
-
</body>
|
|
45
|
-
</html>
|
|
46
|
-
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const arrayIn = [{ vendor_uLID: '5e793a0411d2bef2e375cd00', productVariations: [ { variationName: 'Colour', variationOptions: [ { name: 'Blue', record_uLID: '6afa239e-ce53-40eb-addc-836d8ecc0051', }, { name: 'yellow', record_uLID: '66654830-6850-490a-8eaf-9d505e3e4672', } ], }, { variationName: 'Pattern', variationOptions: [ { name: 'Bold', record_uLID: '6afa239e-ce53-40eb-addc-836d8ecc0055', }, { name: 'Spotted', record_uLID: '66654830-6850-490a-8eaf-9d505e3e4671', }, { name: 'Stripped', record_uLID: 'ec9b5fbe-6428-4a67-aab8-9a23cdce2f9f', }, ], }, ], }, { vendor_uLID: '5e7bb266071f9601b6ad8f4e', productVariations: [ { variationName: 'Colour', variationOptions: [ { name: 'Blue', record_uLID: '6afa239e-ce53-40eb-addc-836d8ecc0051', }, { name: 'yellow', record_uLID: '66654830-6850-490a-8eaf-9d505e3e4672', } ], }, { variationName: 'Pattern', variationOptions: [ { name: 'Bold', record_uLID: '6afa239e-ce53-40eb-addc-836d8ecc0055', }, { name: 'Spotted', record_uLID: '66654830-6850-490a-8eaf-9d505e3e4671', }, { name: 'Stripped', record_uLID: 'ec9b5fbe-6428-4a67-aab8-9a23cdce2f9f', }, ], }, ], }, { vendor_uLID: '5e80971b1540161f3279e29e', productVariations: [ { variationName: 'Pattern', variationOptions: [ { name: 'Bold', record_uLID: '6afa239e-ce53-40eb-addc-836d8ecc0055', }, { name: 'Spotted', record_uLID: '66654830-6850-490a-8eaf-9d505e3e4671' } ] } ] } ]
|
|
4
|
-
|
|
5
|
-
const { pipe, fork, assign, tap, map, reduce, get } = require('..')
|
|
6
|
-
|
|
7
|
-
const trace = tap(console.log)
|
|
8
|
-
|
|
9
|
-
const identity = x => x
|
|
10
|
-
|
|
11
|
-
const incMap = (m, { record_uLID, vendor_uLID }) => {
|
|
12
|
-
if (m.has(record_uLID)) {
|
|
13
|
-
m.get(record_uLID).add(vendor_uLID)
|
|
14
|
-
} else {
|
|
15
|
-
m.set(record_uLID, new Set([vendor_uLID]))
|
|
16
|
-
}
|
|
17
|
-
return m
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/*
|
|
21
|
-
// normal version
|
|
22
|
-
const createRecordToVendorMap = pipe([
|
|
23
|
-
flatMap(vendor => pipe([
|
|
24
|
-
get('productVariations'),
|
|
25
|
-
flatMap(pipe([
|
|
26
|
-
get('variationOptions'),
|
|
27
|
-
map(fork({
|
|
28
|
-
record_uLID: get('record_uLID'),
|
|
29
|
-
vendor_uLID: () => vendor.vendor_uLID,
|
|
30
|
-
})),
|
|
31
|
-
]))
|
|
32
|
-
])(vendor)),
|
|
33
|
-
reduce(incMap, new Map()),
|
|
34
|
-
])
|
|
35
|
-
|
|
36
|
-
// transducer version
|
|
37
|
-
reduce(flatMap(vendor => pipe([
|
|
38
|
-
get('productVariations'),
|
|
39
|
-
flatMap(pipe([
|
|
40
|
-
get('variationOptions'),
|
|
41
|
-
map(fork({
|
|
42
|
-
record_uLID: get('record_uLID'),
|
|
43
|
-
vendor_uLID: () => vendor.vendor_uLID,
|
|
44
|
-
})),
|
|
45
|
-
]))
|
|
46
|
-
])(vendor))(incMap), new Map())
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
const combineMaps = (mA, mB) => {
|
|
50
|
-
for (const [record_uLID, linkedVendors] of mB) {
|
|
51
|
-
for (const vendor_uLID of linkedVendors) {
|
|
52
|
-
incMap(mA, { record_uLID, vendor_uLID })
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return mA
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/*
|
|
59
|
-
* vendors => Map { record_uLID -> Set { vendor_uLID } }
|
|
60
|
-
*/
|
|
61
|
-
const createRecordToVendorMap = pipe([
|
|
62
|
-
map(vendor => pipe([ // for each vendor of vendors
|
|
63
|
-
get('productVariations'),
|
|
64
|
-
map(pipe([ // for each productVariation of productVariations
|
|
65
|
-
get('variationOptions'),
|
|
66
|
-
reduce(map(fork({ // for each record of each variationOption of each variationOptions, create a new object
|
|
67
|
-
record_uLID: get('record_uLID'),
|
|
68
|
-
vendor_uLID: () => vendor.vendor_uLID,
|
|
69
|
-
}))(incMap), new Map()), // reduce the new object via incMap into a new Map()
|
|
70
|
-
])),
|
|
71
|
-
reduce(combineMaps, new Map()), // combine array of Maps into one Map
|
|
72
|
-
])(vendor)),
|
|
73
|
-
reduce(combineMaps, new Map()), // combine array of Maps into one Map
|
|
74
|
-
])
|
|
75
|
-
|
|
76
|
-
/*
|
|
77
|
-
* vendors => variationOptions_with_linkedVendors
|
|
78
|
-
*/
|
|
79
|
-
const linkVendorsToProductVariations = pipe([
|
|
80
|
-
fork({
|
|
81
|
-
recordToVendorMap: createRecordToVendorMap, // vendors => Map { record_uLID => Set { vendor_uLID } }
|
|
82
|
-
vendors: identity,
|
|
83
|
-
}),
|
|
84
|
-
({ recordToVendorMap, vendors }) => map(pipe([ // for each vendor of vendors
|
|
85
|
-
get('productVariations'),
|
|
86
|
-
map(fork({ // for each productVariation of productVariations, create a new object { variationName, variationOptions }
|
|
87
|
-
variationName: get('variationName'),
|
|
88
|
-
variationOptions: pipe([
|
|
89
|
-
get('variationOptions'),
|
|
90
|
-
map(assign({ // for each variationOption of variationOptions, assign the object { ...variationOption, linkedVendors }
|
|
91
|
-
linkedVendors: pipe([
|
|
92
|
-
get('record_uLID'),
|
|
93
|
-
record_uLID => recordToVendorMap.get(record_uLID) || new Set(),
|
|
94
|
-
Array.from,
|
|
95
|
-
]),
|
|
96
|
-
})),
|
|
97
|
-
]),
|
|
98
|
-
})),
|
|
99
|
-
]))(vendors),
|
|
100
|
-
])
|
|
101
|
-
|
|
102
|
-
console.log(JSON.stringify(
|
|
103
|
-
linkVendorsToProductVariations(arrayIn),
|
|
104
|
-
null,
|
|
105
|
-
2,
|
|
106
|
-
))
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { pipe, map, filter, transform, get, and, gt } = require('..')
|
|
4
|
-
|
|
5
|
-
const groups = [
|
|
6
|
-
{
|
|
7
|
-
id: 0,
|
|
8
|
-
name: "All",
|
|
9
|
-
selected: false
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
id: -1,
|
|
13
|
-
name: "All",
|
|
14
|
-
selected: true
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
id: 1,
|
|
18
|
-
name: "Group1",
|
|
19
|
-
selected: false
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
id: 2,
|
|
23
|
-
name: "Group2",
|
|
24
|
-
selected: false
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
id: 3,
|
|
28
|
-
name: "Group3",
|
|
29
|
-
selected: false
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: 4,
|
|
33
|
-
name: "Group4",
|
|
34
|
-
selected: true
|
|
35
|
-
},
|
|
36
|
-
]
|
|
37
|
-
|
|
38
|
-
const getPositiveSelectedIDs = pipe([
|
|
39
|
-
filter(and([
|
|
40
|
-
gt(get('id'), 0),
|
|
41
|
-
get('selected'),
|
|
42
|
-
])),
|
|
43
|
-
map(get('id')),
|
|
44
|
-
])
|
|
45
|
-
|
|
46
|
-
const ids = transform(getPositiveSelectedIDs, [])(groups) // => [4]
|
|
47
|
-
|
|
48
|
-
console.log('Extracted:', ids)
|
|
49
|
-
|
|
50
|
-
// https://stackoverflow.com/questions/60653070/extract-id-from-array-using-map-with-condition-javascript/61967120#61967120
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { map, tap, transform } = require('..')
|
|
4
|
-
|
|
5
|
-
function SimpleQueue({ size }) {
|
|
6
|
-
this.size = size
|
|
7
|
-
this.buffer = []
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
SimpleQueue.prototype.push = function(item) {
|
|
11
|
-
this.buffer.push(item)
|
|
12
|
-
if (this.buffer.length > this.size) {
|
|
13
|
-
this.buffer.shift()
|
|
14
|
-
}
|
|
15
|
-
return this
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
SimpleQueue.prototype[Symbol.iterator] = function*() {
|
|
19
|
-
for (const item of this.buffer) {
|
|
20
|
-
yield item
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const average = iterable => {
|
|
25
|
-
let sum = 0, count = 0
|
|
26
|
-
for (const item of iterable) {
|
|
27
|
-
sum += item
|
|
28
|
-
count += 1
|
|
29
|
-
}
|
|
30
|
-
return sum / count
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const floatingPointAverage = ({ historySize }) => {
|
|
34
|
-
const queue = new SimpleQueue({ size: historySize })
|
|
35
|
-
return item => {
|
|
36
|
-
queue.push(item)
|
|
37
|
-
const avg = average(queue)
|
|
38
|
-
console.log(queue, avg)
|
|
39
|
-
return avg
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const numbersStream = {
|
|
44
|
-
/* ... */
|
|
45
|
-
[Symbol.asyncIterator]: async function*() {
|
|
46
|
-
for (let i = 0; i < 1000; i++) yield i
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
transform(
|
|
51
|
-
map(floatingPointAverage({ historySize: 50 })),
|
|
52
|
-
null,
|
|
53
|
-
)(numbersStream)
|
|
54
|
-
|
|
55
|
-
// https://stackoverflow.com/questions/60960080/javascript-transducers-for-a-data-flow-project/61944627#61944627
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { pipe, fork, switchCase, get } = require('rubico')
|
|
4
|
-
|
|
5
|
-
const jira = { // this is a mock jira.board.getAllBoards api
|
|
6
|
-
board: {
|
|
7
|
-
getAllBoards: ({ type, startAt }) => {
|
|
8
|
-
if (startAt === 0) return {
|
|
9
|
-
isLast: false,
|
|
10
|
-
values: [{ _id: 1, type: 'scrum', title: 'Hello' }],
|
|
11
|
-
startAt: 0,
|
|
12
|
-
}
|
|
13
|
-
if (startAt === 1) return {
|
|
14
|
-
isLast: false,
|
|
15
|
-
values: [{ _id: 2, type: 'scrum', title: 'World' }],
|
|
16
|
-
startAt: 1,
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
isLast: true,
|
|
20
|
-
values: [],
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const getAllBoards = boards => pipe([
|
|
27
|
-
fork({
|
|
28
|
-
type: () => 'scrum',
|
|
29
|
-
startAt: get('startAt'),
|
|
30
|
-
}),
|
|
31
|
-
jira.board.getAllBoards,
|
|
32
|
-
switchCase([
|
|
33
|
-
get('isLast'),
|
|
34
|
-
response => boards.concat(response.values),
|
|
35
|
-
response => getAllBoards(boards.concat(response.values))({
|
|
36
|
-
startAt: response.startAt + response.values.length,
|
|
37
|
-
})
|
|
38
|
-
]),
|
|
39
|
-
])
|
|
40
|
-
|
|
41
|
-
const boards = getAllBoards([])({ startAt: 0 }) // => [...boards]
|
|
42
|
-
|
|
43
|
-
console.log(boards)
|
|
44
|
-
|
|
45
|
-
// https://stackoverflow.com/questions/55819017/how-do-i-return-an-entire-paged-set-from-the-jira-api-using-ramda/61909364#61909364
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { pipe, map, reduce, get } = require('rubico')
|
|
4
|
-
const io = require('socket.io')()
|
|
5
|
-
|
|
6
|
-
const rooms = ['room1', 'room2', 'room3']
|
|
7
|
-
|
|
8
|
-
const getClientsInRoom = room => new Promise((resolve, reject) => {
|
|
9
|
-
io.in(room).clients((err, clients) => {
|
|
10
|
-
if (err) {
|
|
11
|
-
reject(err);
|
|
12
|
-
} else {
|
|
13
|
-
resolve(clients);
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const add = (a, b) => a + b
|
|
19
|
-
|
|
20
|
-
const getTotalClientsCount = pipe([
|
|
21
|
-
map(getClientsInRoom), // [...rooms] => [[...clients], [...clients], ...]
|
|
22
|
-
map(get('length')), // [[...clients], [...clients], ...] => [16, 1, 20, 0, ...]
|
|
23
|
-
reduce(add, 0), // [16, 1, 20, 0, ...] => 0 + 16 + 1 + 20 + 0 + ...
|
|
24
|
-
]);
|
|
25
|
-
|
|
26
|
-
async function main() {
|
|
27
|
-
const rooms = ['room1', 'room2', 'room3']
|
|
28
|
-
const totalCount = await getTotalClientsCount(rooms)
|
|
29
|
-
console.log(totalCount)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
main()
|
|
33
|
-
|
|
34
|
-
// https://stackoverflow.com/questions/61802050/how-to-make-socket-io-asynchronous-method-synchronous/61924033#61924033
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { pipe, fork, get } = require('rubico')
|
|
4
|
-
const kafka = require('kafka-node'),
|
|
5
|
-
|
|
6
|
-
// safely accesses properties with get
|
|
7
|
-
const safeParseTopic = (topic, data) => get([topic, 0, 0])(data)
|
|
8
|
-
|
|
9
|
-
const fetchLatestOffset = client => topic => new Promise((resolve, reject) => {
|
|
10
|
-
new kafka.Offset(client).fetch(
|
|
11
|
-
[{ topic: topic, partition: 0, time: -1 }],
|
|
12
|
-
(err, data) => err ? reject(err) : resolve(safeParseTopic(topic, data)),
|
|
13
|
-
)
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
// it's recommend to create new client for different consumers
|
|
17
|
-
// https://www.npmjs.com/package/kafka-node#consumer
|
|
18
|
-
// ({ topic, offset }) -> consumerInstance
|
|
19
|
-
const makeConsumerInstance = client => ({ topic, offset }) => (
|
|
20
|
-
new kafka.Consumer(
|
|
21
|
-
client,
|
|
22
|
-
[{ topic, offset, partition: 0 }],
|
|
23
|
-
{ autoCommit: true },
|
|
24
|
-
)
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
// consumerInstance -> messages
|
|
28
|
-
const consume = consumerInstance => new Promise((resolve, reject) => {
|
|
29
|
-
const messages = []
|
|
30
|
-
|
|
31
|
-
consumerInstance.on('message', message => {
|
|
32
|
-
messages.push(message)
|
|
33
|
-
if (message.offset == (message.highWaterOffset - 1)) {
|
|
34
|
-
resolve(messages)
|
|
35
|
-
// TODO: cleanup consumerInstance here
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
// handles a termination signal from the producer
|
|
40
|
-
consumerInstance.on('end', () => resolve(messages))
|
|
41
|
-
|
|
42
|
-
consumerInstance.on('error', reject)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
// topic -> messages
|
|
46
|
-
// pipe chains async functions together
|
|
47
|
-
const consumer = topic => {
|
|
48
|
-
const client = new kafka.KafkaClient({ kafkaHost: 'kafka:9092' })
|
|
49
|
-
return pipe([
|
|
50
|
-
fetchLatestOffset(client), // topic -> latestOffset
|
|
51
|
-
|
|
52
|
-
fork({
|
|
53
|
-
topic: () => topic,
|
|
54
|
-
offset: latestOffset => latestOffset,
|
|
55
|
-
}), // latestOffset -> ({ topic, offset })
|
|
56
|
-
|
|
57
|
-
makeConsumerInstance(client), // ({ topic, offset }) -> consumerInstance
|
|
58
|
-
|
|
59
|
-
consume, // consumerInstance -> messages
|
|
60
|
-
])(topic)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
module.exports = { consumer }
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fetch = require('node-fetch')
|
|
4
|
-
|
|
5
|
-
const todoIDs = [1, 2, 3, 4, 5]
|
|
6
|
-
|
|
7
|
-
// promise chains
|
|
8
|
-
Promise.resolve(todoIDs.filter(id => id <= 3))
|
|
9
|
-
.then(filtered => Promise.all(filtered.map(
|
|
10
|
-
id => `https://jsonplaceholder.typicode.com/todos/${id}`
|
|
11
|
-
)))
|
|
12
|
-
.then(urls => Promise.all(urls.map(url => fetch(url))))
|
|
13
|
-
.then(responses => Promise.all(responses.map(res => res.json())))
|
|
14
|
-
.then(data => data.map(x => console.log('promise chains', x))) // > {...} {...} {...}
|
|
15
|
-
|
|
16
|
-
// async await
|
|
17
|
-
void (async () => {
|
|
18
|
-
const filtered = todoIDs.filter(id => id <= 3)
|
|
19
|
-
const urls = await Promise.all(filtered.map(id => `https://jsonplaceholder.typicode.com/todos/${id}`))
|
|
20
|
-
const responses = await Promise.all(urls.map(url => fetch(url)))
|
|
21
|
-
const data = await Promise.all(responses.map(res => res.json()))
|
|
22
|
-
data.map(x => console.log('async/await', x)) // > {...} {...} {...}
|
|
23
|
-
})()
|
|
24
|
-
|
|
25
|
-
// ramda
|
|
26
|
-
const R = require('ramda')
|
|
27
|
-
|
|
28
|
-
R.pipe(
|
|
29
|
-
R.filter(id => id <= 3),
|
|
30
|
-
R.map(id => `https://jsonplaceholder.typicode.com/todos/${id}`),
|
|
31
|
-
R.map(fetch),
|
|
32
|
-
R.map(R.andThen(res => res.json())),
|
|
33
|
-
R.map(R.andThen(x => console.log('ramda', x))), // > {...} {...} {...}
|
|
34
|
-
)(todoIDs)
|
|
35
|
-
|
|
36
|
-
const { pipe, map, filter, transform } = require('..')
|
|
37
|
-
|
|
38
|
-
// rubico
|
|
39
|
-
pipe([
|
|
40
|
-
filter(id => id <= 3),
|
|
41
|
-
map(id => `https://jsonplaceholder.typicode.com/todos/${id}`),
|
|
42
|
-
map(fetch),
|
|
43
|
-
map(res => res.json()),
|
|
44
|
-
map(x => console.log('rubico', x)), // > {...} {...} {...}
|
|
45
|
-
])(todoIDs)
|
|
46
|
-
|
|
47
|
-
// transform - a special way to consume transducers
|
|
48
|
-
// transform(null, pipe(...))(x) transforms input x to null according to transducer pipe([...])
|
|
49
|
-
transform(pipe([
|
|
50
|
-
filter(id => id <= 3),
|
|
51
|
-
map(id => `https://jsonplaceholder.typicode.com/todos/${id}`),
|
|
52
|
-
map(fetch),
|
|
53
|
-
map(res => res.json()),
|
|
54
|
-
map(x => console.log('transform', x)), // > {...} {...} {...}
|
|
55
|
-
]), null)(todoIDs)
|