rubico 2.7.3 → 2.7.5
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/LICENSE +1 -1
- package/README.md +27 -30
- package/Transducer.d.ts +10 -10
- package/Transducer.js +65 -69
- package/__.js +1 -1
- package/_internal/FlatMappingIterator.js +1 -1
- package/_internal/MappingIterator.d.ts +1 -1
- package/_internal/MappingIterator.js +1 -1
- package/_internal/arrayFilter.js +6 -6
- package/_internal/arrayFilterIndexes.js +7 -7
- package/_internal/arrayFilterWithIndex.js +6 -6
- package/_internal/arrayFind.js +7 -7
- package/_internal/arrayFlatten.js +25 -25
- package/_internal/arrayForEach.d.ts +1 -1
- package/_internal/arrayForEach.js +1 -1
- package/_internal/arrayForEachSeries.js +1 -1
- package/_internal/arrayMap.d.ts +2 -2
- package/_internal/arrayMap.js +5 -5
- package/_internal/arrayMapPool.d.ts +1 -1
- package/_internal/arrayMapPool.js +10 -10
- package/_internal/arrayMapRate.js +4 -4
- package/_internal/arrayMapSeries.d.ts +1 -1
- package/_internal/arrayMapSeries.js +8 -8
- package/_internal/arrayMapWithIndex.js +4 -4
- package/_internal/arrayReduce.js +1 -1
- package/_internal/asyncGeneratorFunctionForEach.js +3 -3
- package/_internal/asyncGeneratorFunctionMap.js +3 -3
- package/_internal/asyncIteratorFind.js +3 -3
- package/_internal/asyncIteratorForEach.d.ts +1 -1
- package/_internal/asyncIteratorForEach.js +3 -3
- package/_internal/asyncIteratorForEachSeries.js +3 -3
- package/_internal/asyncIteratorToArray.js +2 -2
- package/_internal/copyDeep.js +12 -12
- package/_internal/funcAll.js +3 -3
- package/_internal/funcAllSeries.js +6 -6
- package/_internal/funcObjectAll.js +4 -4
- package/_internal/functionArrayAll.js +3 -3
- package/_internal/functionArrayAllSeries.js +6 -6
- package/_internal/functionObjectAll.js +4 -4
- package/_internal/generatorFunctionForEach.js +3 -3
- package/_internal/generatorFunctionMap.js +3 -3
- package/_internal/generatorFunctionReduce.js +1 -1
- package/_internal/iteratorEvery.js +2 -2
- package/_internal/iteratorFind.js +7 -7
- package/_internal/iteratorForEach.d.ts +1 -1
- package/_internal/iteratorForEach.js +3 -3
- package/_internal/iteratorForEachSeries.js +1 -1
- package/_internal/iteratorReduce.d.ts +1 -1
- package/_internal/iteratorReduce.js +2 -2
- package/_internal/iteratorSome.js +2 -2
- package/_internal/mapFilter.js +4 -4
- package/_internal/mapMap.d.ts +1 -1
- package/_internal/mapMap.js +6 -6
- package/_internal/mapMapPool.js +10 -10
- package/_internal/mapMapSeries.js +10 -10
- package/_internal/objectFilter.js +6 -6
- package/_internal/objectFlatMap.d.ts +1 -1
- package/_internal/objectFlatMap.js +1 -1
- package/_internal/objectFlatten.js +14 -14
- package/_internal/objectMap.js +3 -3
- package/_internal/objectMapOwn.js +3 -3
- package/_internal/objectMapPool.js +10 -10
- package/_internal/objectMapSeries.js +9 -9
- package/_internal/objectReduce.d.ts +1 -1
- package/_internal/objectReduce.js +2 -2
- package/_internal/reducerAllSync.d.ts +2 -2
- package/_internal/reducerAllSync.js +2 -2
- package/_internal/reducerAnySync.d.ts +1 -1
- package/_internal/reducerAnySync.js +2 -2
- package/_internal/reducerConcat.d.ts +1 -1
- package/_internal/reducerConcat.js +4 -4
- package/_internal/reducerConcatSync.js +2 -2
- package/_internal/reducerEvery.d.ts +2 -2
- package/_internal/reducerEvery.js +4 -4
- package/_internal/reducerFilter.d.ts +2 -2
- package/_internal/reducerFilter.js +5 -5
- package/_internal/reducerFlatten.js +3 -3
- package/_internal/reducerForEach.d.ts +2 -2
- package/_internal/reducerForEach.js +5 -5
- package/_internal/reducerMap.d.ts +1 -1
- package/_internal/reducerMap.js +5 -5
- package/_internal/reducerSome.d.ts +2 -2
- package/_internal/reducerSome.js +4 -4
- package/_internal/reducerTryCatch.d.ts +2 -2
- package/_internal/reducerTryCatch.js +8 -8
- package/_internal/setFilter.d.ts +1 -1
- package/_internal/setFilter.js +5 -5
- package/_internal/setFlatten.js +24 -24
- package/_internal/setMap.d.ts +1 -1
- package/_internal/setMap.js +6 -6
- package/_internal/setMapPool.js +9 -9
- package/_internal/setMapSeries.js +10 -10
- package/_internal/streamFlatExtend.js +25 -25
- package/_internal/streamFlatMap.js +2 -2
- package/all.js +3 -3
- package/and.js +5 -2
- package/assign.js +2 -2
- package/compose.js +6 -2
- package/curry.js +5 -12
- package/dist/Transducer.es.js +24 -24
- package/dist/Transducer.es.min.js +1 -1
- package/dist/Transducer.js +24 -24
- package/dist/Transducer.min.js +1 -1
- package/dist/Transducer.mjs +24 -24
- 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 +14 -14
- package/dist/all.es.min.js +1 -1
- package/dist/all.js +14 -14
- package/dist/all.min.js +1 -1
- package/dist/all.mjs +14 -14
- 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 +5 -5
- package/dist/assign.es.min.js +1 -1
- package/dist/assign.js +5 -5
- package/dist/assign.min.js +1 -1
- package/dist/assign.mjs +5 -5
- 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 +7 -7
- package/dist/every.es.min.js +1 -1
- package/dist/every.js +7 -7
- package/dist/every.min.js +1 -1
- package/dist/every.mjs +7 -7
- package/dist/filter.es.js +21 -21
- package/dist/filter.es.min.js +1 -1
- package/dist/filter.js +21 -21
- package/dist/filter.min.js +1 -1
- package/dist/filter.mjs +21 -21
- package/dist/flatMap.es.js +82 -82
- package/dist/flatMap.es.min.js +1 -1
- package/dist/flatMap.js +82 -82
- package/dist/flatMap.min.js +1 -1
- package/dist/flatMap.mjs +82 -82
- package/dist/forEach.es.js +7 -7
- package/dist/forEach.es.min.js +1 -1
- package/dist/forEach.js +7 -7
- package/dist/forEach.min.js +1 -1
- package/dist/forEach.mjs +7 -7
- 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 +83 -83
- package/dist/map.es.min.js +1 -1
- package/dist/map.js +83 -83
- package/dist/map.min.js +1 -1
- package/dist/map.mjs +83 -83
- 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 +13 -13
- package/dist/omit.es.min.js +1 -1
- package/dist/omit.js +13 -13
- package/dist/omit.min.js +1 -1
- package/dist/omit.mjs +13 -13
- 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 +5 -5
- package/dist/reduce.es.min.js +1 -1
- package/dist/reduce.js +5 -5
- package/dist/reduce.min.js +1 -1
- package/dist/reduce.mjs +5 -5
- package/dist/rubico.es.js +215 -215
- package/dist/rubico.es.min.js +1 -1
- package/dist/rubico.global.js +215 -215
- package/dist/rubico.global.min.js +1 -1
- package/dist/rubico.js +215 -215
- package/dist/rubico.min.js +1 -1
- package/dist/rubico.mjs +215 -215
- 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 +8 -8
- package/dist/some.es.min.js +1 -1
- package/dist/some.js +8 -8
- package/dist/some.min.js +1 -1
- package/dist/some.mjs +8 -8
- 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 +1 -1
- package/dist/tap.es.min.js +1 -1
- package/dist/tap.js +1 -1
- package/dist/tap.min.js +1 -1
- package/dist/tap.mjs +1 -1
- 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 +5 -5
- package/dist/transform.es.min.js +1 -1
- package/dist/transform.js +5 -5
- package/dist/transform.min.js +1 -1
- package/dist/transform.mjs +5 -5
- 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 +8 -8
- package/dist/x/append.es.min.js +1 -1
- package/dist/x/append.js +8 -8
- package/dist/x/append.min.js +1 -1
- package/dist/x/append.mjs +8 -8
- 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 +69 -37
- package/dist/x/defaultsDeep.es.min.js +2 -2
- package/dist/x/defaultsDeep.js +69 -37
- package/dist/x/defaultsDeep.min.js +2 -2
- package/dist/x/defaultsDeep.mjs +69 -37
- package/dist/x/differenceWith.es.js +14 -14
- package/dist/x/differenceWith.es.min.js +1 -1
- package/dist/x/differenceWith.js +14 -14
- package/dist/x/differenceWith.min.js +1 -1
- package/dist/x/differenceWith.mjs +14 -14
- package/dist/x/filterOut.es.js +21 -21
- package/dist/x/filterOut.es.min.js +1 -1
- package/dist/x/filterOut.js +21 -21
- package/dist/x/filterOut.min.js +1 -1
- package/dist/x/filterOut.mjs +21 -21
- package/dist/x/find.es.js +18 -18
- package/dist/x/find.es.min.js +1 -1
- package/dist/x/find.js +18 -18
- package/dist/x/find.min.js +1 -1
- package/dist/x/find.mjs +18 -18
- 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 +82 -82
- package/dist/x/flatten.es.min.js +1 -1
- package/dist/x/flatten.js +82 -82
- package/dist/x/flatten.min.js +1 -1
- package/dist/x/flatten.mjs +82 -82
- package/dist/x/groupBy.es.js +17 -17
- package/dist/x/groupBy.es.min.js +1 -1
- package/dist/x/groupBy.js +17 -17
- package/dist/x/groupBy.min.js +1 -1
- package/dist/x/groupBy.mjs +17 -17
- 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 +6 -6
- package/dist/x/maxBy.es.min.js +1 -1
- package/dist/x/maxBy.js +6 -6
- package/dist/x/maxBy.min.js +1 -1
- package/dist/x/maxBy.mjs +6 -6
- 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 +83 -83
- package/dist/x/pluck.es.min.js +1 -1
- package/dist/x/pluck.js +83 -83
- package/dist/x/pluck.min.js +1 -1
- package/dist/x/pluck.mjs +83 -83
- package/dist/x/prepend.es.js +8 -8
- package/dist/x/prepend.es.min.js +1 -1
- package/dist/x/prepend.js +8 -8
- package/dist/x/prepend.min.js +1 -1
- package/dist/x/prepend.mjs +8 -8
- 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 +1 -1
- package/dist/x/trace.es.min.js +1 -1
- package/dist/x/trace.js +1 -1
- package/dist/x/trace.min.js +1 -1
- package/dist/x/trace.mjs +1 -1
- package/dist/x/unionWith.es.js +39 -39
- package/dist/x/unionWith.es.min.js +1 -1
- package/dist/x/unionWith.js +39 -39
- package/dist/x/unionWith.min.js +1 -1
- package/dist/x/unionWith.mjs +39 -39
- package/dist/x/uniq.es.js +1 -1
- package/dist/x/uniq.es.min.js +1 -1
- package/dist/x/uniq.js +1 -1
- package/dist/x/uniq.min.js +1 -1
- package/dist/x/uniq.mjs +1 -1
- package/dist/x/unless.es.js +1 -1
- package/dist/x/unless.es.min.js +1 -1
- package/dist/x/unless.js +1 -1
- package/dist/x/unless.min.js +1 -1
- package/dist/x/unless.mjs +1 -1
- package/dist/x/values.es.js +1 -1
- package/dist/x/values.es.min.js +1 -1
- package/dist/x/values.js +1 -1
- package/dist/x/values.min.js +1 -1
- package/dist/x/values.mjs +1 -1
- package/dist/x/when.es.js +1 -1
- package/dist/x/when.es.min.js +1 -1
- package/dist/x/when.js +1 -1
- package/dist/x/when.min.js +1 -1
- package/dist/x/when.mjs +1 -1
- package/eq.js +32 -10
- package/es.js +215 -215
- package/every.d.ts +1 -1
- package/every.js +6 -3
- package/filter.d.ts +3 -3
- package/filter.js +14 -14
- package/flatMap.d.ts +9 -9
- package/flatMap.js +9 -9
- package/forEach.d.ts +1 -1
- package/forEach.js +19 -15
- package/global.js +1 -0
- package/gt.js +30 -13
- package/gte.js +31 -12
- package/index.js +215 -215
- package/lt.js +28 -9
- package/lte.js +34 -15
- package/map.d.ts +3 -3
- package/map.js +31 -31
- package/monad/Mux.benchmark.js +1 -1
- package/monad/Mux.js +6 -6
- package/monad/Struct.js +2 -2
- package/not.js +15 -7
- package/or.js +5 -2
- package/package.json +1 -1
- package/pipe.js +7 -13
- package/reduce.d.ts +7 -7
- package/reduce.js +16 -16
- package/some.d.ts +1 -1
- package/some.js +6 -3
- package/switchCase.d.ts +1 -1
- package/switchCase.js +7 -4
- package/tap.js +14 -4
- package/thunkify.js +2 -0
- package/transform.d.ts +1 -1
- package/transform.js +6 -15
- package/tryCatch.js +8 -2
- package/x/README.md +8 -8
- package/x/append.d.ts +2 -2
- package/x/append.js +8 -8
- package/x/defaultsDeep.js +94 -57
- package/x/defaultsDeep.test.js +24 -1
- package/x/differenceWith.js +13 -13
- package/x/find.d.ts +1 -1
- package/x/find.js +1 -1
- package/x/find.test.js +2 -2
- package/x/findIndex.test.js +1 -1
- package/x/first.d.ts +1 -1
- package/x/first.js +1 -1
- package/x/first.test.js +1 -1
- package/x/groupBy.d.ts +1 -1
- package/x/groupBy.js +13 -13
- package/x/last.d.ts +1 -1
- package/x/last.js +1 -1
- package/x/last.test.js +1 -1
- package/x/maxBy.d.ts +7 -7
- package/x/maxBy.js +13 -13
- package/x/maxBy.test.js +5 -5
- package/x/pluck.test.js +1 -1
- package/x/prepend.d.ts +2 -2
- package/x/prepend.js +8 -8
- package/x/size.d.ts +1 -1
- package/x/size.js +1 -1
- package/x/unionWith.js +11 -11
- package/x/unionWith.test.js +5 -5
- package/global.d.ts +0 -1
package/reduce.js
CHANGED
|
@@ -23,17 +23,17 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
23
23
|
* ```coffeescript [specscript]
|
|
24
24
|
* type Foldable = Array|Set|Map|Generator|AsyncGenerator|{ reduce: function }|Object
|
|
25
25
|
*
|
|
26
|
-
* type
|
|
26
|
+
* type SyncOrAsyncReducer = (
|
|
27
27
|
* accumulator any,
|
|
28
|
-
*
|
|
28
|
+
* element any,
|
|
29
29
|
* indexOrKey number|string|any,
|
|
30
30
|
* foldable Foldable
|
|
31
31
|
* )=>(nextAccumulator Promise|any)
|
|
32
32
|
*
|
|
33
|
-
* type
|
|
33
|
+
* type UnarySyncOrAsyncResolver = any=>Promise|any
|
|
34
34
|
*
|
|
35
|
-
* reducer
|
|
36
|
-
* initial
|
|
35
|
+
* reducer SyncOrAsyncReducer
|
|
36
|
+
* initial UnarySyncOrAsyncResolver|any
|
|
37
37
|
*
|
|
38
38
|
* reduce(foldable Promise|Foldable, reducer, initial?) -> result Promise|any
|
|
39
39
|
* reduce(reducer, initial?)(foldable Foldable) -> result Promise|any
|
|
@@ -51,11 +51,11 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
51
51
|
* * `object with .reduce method`
|
|
52
52
|
* * `object`
|
|
53
53
|
*
|
|
54
|
-
* The reducing operation is dictated by a provided reducer function, which defines a transformation between the accumulator and a given
|
|
54
|
+
* The reducing operation is dictated by a provided reducer function, which defines a transformation between the accumulator and a given element of the foldable.
|
|
55
55
|
*
|
|
56
56
|
* ```javascript
|
|
57
|
-
* const reducer = function (accumulator,
|
|
58
|
-
* // nextAccumulator is the result of some operation between accumulator and
|
|
57
|
+
* const reducer = function (accumulator, element) {
|
|
58
|
+
* // nextAccumulator is the result of some operation between accumulator and element
|
|
59
59
|
* // and becomes the accumulator for the next iteration and invocation of the reducer
|
|
60
60
|
* return nextAccumulator
|
|
61
61
|
* }
|
|
@@ -67,7 +67,7 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
67
67
|
* ```coffeescript [specscript]
|
|
68
68
|
* reducer(
|
|
69
69
|
* accumulator any,
|
|
70
|
-
*
|
|
70
|
+
* element any,
|
|
71
71
|
* index number,
|
|
72
72
|
* fold Array
|
|
73
73
|
* ) -> nextAccumulator Promise|any
|
|
@@ -77,7 +77,7 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
77
77
|
* ```coffeescript [specscript]
|
|
78
78
|
* reducer(
|
|
79
79
|
* accumulator any,
|
|
80
|
-
*
|
|
80
|
+
* element any
|
|
81
81
|
* ) -> nextAccumulator Promise|any
|
|
82
82
|
* ```
|
|
83
83
|
*
|
|
@@ -85,7 +85,7 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
85
85
|
* ```coffeescript [specscript]
|
|
86
86
|
* reducer(
|
|
87
87
|
* accumulator any,
|
|
88
|
-
*
|
|
88
|
+
* element any,
|
|
89
89
|
* key any,
|
|
90
90
|
* fold Map
|
|
91
91
|
* ) -> nextAccumulator Promise|any
|
|
@@ -95,7 +95,7 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
95
95
|
* ```coffeescript [specscript]
|
|
96
96
|
* reducer(
|
|
97
97
|
* accumulator any,
|
|
98
|
-
*
|
|
98
|
+
* element any
|
|
99
99
|
* ) -> nextAccumulator Promise|any
|
|
100
100
|
* ```
|
|
101
101
|
*
|
|
@@ -103,7 +103,7 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
103
103
|
* ```coffeescript [specscript]
|
|
104
104
|
* reducer(
|
|
105
105
|
* accumulator any,
|
|
106
|
-
*
|
|
106
|
+
* element any
|
|
107
107
|
* ) -> nextAccumulator Promise|any
|
|
108
108
|
* ```
|
|
109
109
|
*
|
|
@@ -113,13 +113,13 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
113
113
|
* ```coffeescript [specscript]
|
|
114
114
|
* reducer(
|
|
115
115
|
* accumulator any,
|
|
116
|
-
*
|
|
116
|
+
* element any,
|
|
117
117
|
* key string,
|
|
118
118
|
* fold Object
|
|
119
119
|
* ) -> nextAccumulator Promise|any
|
|
120
120
|
* ```
|
|
121
121
|
*
|
|
122
|
-
* `reduce` executes a reducer function for each
|
|
122
|
+
* `reduce` executes a reducer function for each element of the array in order. If no initial value is provided, `reduce` uses the first element of the foldable as the initial value and starts iterating from the second element of the foldable.
|
|
123
123
|
*
|
|
124
124
|
* ```javascript [playground]
|
|
125
125
|
* const max = (a, b) => a > b ? a : b
|
|
@@ -128,7 +128,7 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
128
128
|
* console.log(result) // 5
|
|
129
129
|
* ```
|
|
130
130
|
*
|
|
131
|
-
* If an initial value is provided, the accumulator starts as the initial value rather than the first
|
|
131
|
+
* If an initial value is provided, the accumulator starts as the initial value rather than the first element of the foldable.
|
|
132
132
|
*
|
|
133
133
|
* ```javascript [playground]
|
|
134
134
|
* const add = (a, b) => a + b
|
package/some.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export = some;
|
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
14
|
* @description
|
|
15
|
-
* Test a predicate concurrently across all
|
|
15
|
+
* Test a predicate concurrently across all elements of a collection, returning true if any executions return truthy.
|
|
16
16
|
*
|
|
17
17
|
* ```javascript [playground]
|
|
18
18
|
* const isOdd = number => number % 2 == 1
|
package/some.js
CHANGED
|
@@ -41,13 +41,16 @@ const _some = function (collection, predicate) {
|
|
|
41
41
|
* @synopsis
|
|
42
42
|
* ```coffeescript [specscript]
|
|
43
43
|
* type Foldable = Array|Set|Map|Generator|AsyncGenerator|{ reduce: function }|Object
|
|
44
|
+
* type UnarySyncOrAsyncPredicate = any=>Promise|boolean
|
|
44
45
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
46
|
+
* predicate UnarySyncOrAsyncPredicate
|
|
47
|
+
*
|
|
48
|
+
* some(foldable Foldable, predicate) -> Promise|boolean
|
|
49
|
+
* some(predicate)(foldable Foldable) -> Promise|boolean
|
|
47
50
|
* ```
|
|
48
51
|
*
|
|
49
52
|
* @description
|
|
50
|
-
* Test a predicate concurrently across all
|
|
53
|
+
* Test a predicate concurrently across all elements of a foldable, returning true if any executions return true.
|
|
51
54
|
*
|
|
52
55
|
* ```javascript [playground]
|
|
53
56
|
* const isOdd = number => number % 2 == 1
|
package/switchCase.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export = switchCase;
|
|
|
61
61
|
* ])(false).then(console.log) // default
|
|
62
62
|
* ```
|
|
63
63
|
*
|
|
64
|
-
* If every
|
|
64
|
+
* If every element in the conditional array is a nonfunction value, `switchCase` executes eagerly.
|
|
65
65
|
*
|
|
66
66
|
* ```javascript [playground]
|
|
67
67
|
* const age = 26
|
package/switchCase.js
CHANGED
|
@@ -14,8 +14,11 @@ const curryArgs3 = require('./_internal/curryArgs3')
|
|
|
14
14
|
* ```coffeescript [specscript]
|
|
15
15
|
* args Array<any>
|
|
16
16
|
* argsOrPromises Array<Promise|any>
|
|
17
|
+
*
|
|
18
|
+
* type SyncOrAsyncPredicate = (...args)=>Promise|boolean|any
|
|
19
|
+
*
|
|
17
20
|
* conditionalPromisesOrValues Array<Promise|boolean|any>
|
|
18
|
-
* conditionalFuncsOrPromisesOrValues Array<
|
|
21
|
+
* conditionalFuncsOrPromisesOrValues Array<SyncOrAsyncPredicate|Promise|boolean|any>
|
|
19
22
|
*
|
|
20
23
|
* switchCase(conditionalPromisesOrValues) -> Promise|any
|
|
21
24
|
* switchCase(...argsOrPromises, conditionalFuncsOrPromisesOrValues) -> Promise|any
|
|
@@ -58,16 +61,16 @@ const curryArgs3 = require('./_internal/curryArgs3')
|
|
|
58
61
|
* Any function can be replaced with a nonfunction (object or primitive) value to be used directly in the operation.
|
|
59
62
|
*
|
|
60
63
|
* ```javascript [playground]
|
|
61
|
-
* switchCase([
|
|
64
|
+
* switchCase(false, [
|
|
62
65
|
* async function asyncIdentity(value) {
|
|
63
66
|
* return value
|
|
64
67
|
* },
|
|
65
68
|
* 'something',
|
|
66
69
|
* 'default',
|
|
67
|
-
* ])
|
|
70
|
+
* ]).then(console.log) // default
|
|
68
71
|
* ```
|
|
69
72
|
*
|
|
70
|
-
* If every
|
|
73
|
+
* If every element in the conditional array is a nonfunction value, `switchCase` executes eagerly.
|
|
71
74
|
*
|
|
72
75
|
* ```javascript [playground]
|
|
73
76
|
* const age = 26
|
package/tap.js
CHANGED
|
@@ -25,8 +25,12 @@ const _tap = function (args, f) {
|
|
|
25
25
|
* args Array<any>
|
|
26
26
|
* argsOrPromises Array<Promise|any>
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* type SyncOrAsyncFunction = (...args)=>Promise|any
|
|
29
|
+
*
|
|
30
|
+
* f SyncOrAsyncFunction
|
|
31
|
+
*
|
|
32
|
+
* tap(...argsOrPromises, f) -> Promise|args[0]
|
|
33
|
+
* tap(f)(...args) -> Promise|args[0]
|
|
30
34
|
* ```
|
|
31
35
|
*
|
|
32
36
|
* @description
|
|
@@ -107,8 +111,14 @@ const _tapIf = function (predicate, f, args) {
|
|
|
107
111
|
* args Array<any>
|
|
108
112
|
* argsOrPromises Array<Promise|any>
|
|
109
113
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
114
|
+
* type SyncOrAsyncPredicate = (...args)=>Promise|boolean|any
|
|
115
|
+
* type SyncOrAsyncFunction = (...args)=>Promise|any
|
|
116
|
+
*
|
|
117
|
+
* predicate SyncOrAsyncPredicate
|
|
118
|
+
* f SyncOrAsyncFunction
|
|
119
|
+
*
|
|
120
|
+
* tap.if(...argsOrPromises, predicate, f) -> Promise|args[0]
|
|
121
|
+
* tap.if(predicate, f)(...args) -> Promise|args[0]
|
|
112
122
|
* ```
|
|
113
123
|
*
|
|
114
124
|
* @description
|
package/thunkify.js
CHANGED
package/transform.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export = transform;
|
|
|
40
40
|
* * `Set`; concatenation defined by `result.add(...values)`
|
|
41
41
|
* * `TypedArray`; concatenation defined by `result.set(prevResult); result.set(values, offset)`
|
|
42
42
|
* * `{ concat: function }`; concatenation defined by `result.concat(values)`
|
|
43
|
-
* * `{ write: function }`; concatenation defined by `result.write(
|
|
43
|
+
* * `{ write: function }`; concatenation defined by `result.write(element)`
|
|
44
44
|
* * `Object`; concatenation defined by `({ ...result, ...values })`
|
|
45
45
|
*
|
|
46
46
|
* `transform` can transform any of the above collections into any of the other above collections.
|
package/transform.js
CHANGED
|
@@ -22,21 +22,16 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
22
22
|
* @synopsis
|
|
23
23
|
* ```coffeescript [specscript]
|
|
24
24
|
* type Foldable = Array|Set|Map|Generator|AsyncGenerator|{ reduce: function }|Object
|
|
25
|
-
*
|
|
26
|
-
* type
|
|
27
|
-
* accumulator any,
|
|
28
|
-
* value any,
|
|
29
|
-
* )=>(nextAccumulator Promise|any)
|
|
30
|
-
*
|
|
31
|
-
* type Transducer = Reducer=>Reducer
|
|
25
|
+
* type SyncOrAsyncReducer = (accumulator any, value any)=>(nextAccumulator Promise|any)
|
|
26
|
+
* type Transducer = SyncOrAsyncReducer=>SyncOrAsyncReducer
|
|
32
27
|
*
|
|
33
28
|
* type Semigroup =
|
|
34
29
|
* Array|String|Set|TypedArray|{ concat: function }|{ write: function }|Object
|
|
35
30
|
*
|
|
36
|
-
* type
|
|
31
|
+
* type UnarySyncOrAsyncSemigroupResolver = any=>Promise|Semigroup
|
|
37
32
|
*
|
|
38
33
|
* transducer Transducer
|
|
39
|
-
* initial Semigroup
|
|
34
|
+
* initial UnarySyncOrAsyncSemigroupResolver|Semigroup
|
|
40
35
|
*
|
|
41
36
|
* transform(foldable Promise|Foldable, transducer, initial?) -> result Promise|Semigroup
|
|
42
37
|
* transform(transducer, initial?)(foldable Foldable) -> result Promise|Semigroup
|
|
@@ -57,12 +52,8 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
57
52
|
* Transducers, due to their lazy nature, don't have knowledge of the foldable they are transforming. As such, the transducer signature for all foldables is the same:
|
|
58
53
|
*
|
|
59
54
|
* ```coffeescript [specscript]
|
|
60
|
-
* type
|
|
61
|
-
*
|
|
62
|
-
* value any,
|
|
63
|
-
* )=>(nextAccumulator Promise|any)
|
|
64
|
-
*
|
|
65
|
-
* type Transducer = Reducer=>Reducer
|
|
55
|
+
* type SyncOrAsyncReducer = (accumulator any, value any)=>(nextAccumulator Promise|any)
|
|
56
|
+
* type Transducer = SyncOrAsyncReducer=>SyncOrAsyncReducer
|
|
66
57
|
* ```
|
|
67
58
|
*
|
|
68
59
|
* The following data types are considered to be semigroups:
|
package/tryCatch.js
CHANGED
|
@@ -25,8 +25,14 @@ const _tryCatch = function (tryer, catcher, args) {
|
|
|
25
25
|
* args Array<any>
|
|
26
26
|
* argsOrPromises Array<Promise|any>
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* type SyncOrAsyncFunction = (...args)=>Promise|any
|
|
29
|
+
* type SyncOrAsyncCatcher = (error Error|any, ...args)=>Promise|any
|
|
30
|
+
*
|
|
31
|
+
* tryer SyncOrAsyncFunction
|
|
32
|
+
* catcher SyncOrAsyncCatcher
|
|
33
|
+
*
|
|
34
|
+
* tryCatch(tryer, catcher)(...args) -> Promise|any
|
|
35
|
+
* tryCatch(...argsOrPromises, tryer, catcher) -> Promise|any
|
|
30
36
|
* ```
|
|
31
37
|
*
|
|
32
38
|
* @description
|
package/x/README.md
CHANGED
|
@@ -46,7 +46,7 @@ defaultsDeep({
|
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
### find
|
|
49
|
-
get the first
|
|
49
|
+
get the first element in a collection that passes the test
|
|
50
50
|
```javascript
|
|
51
51
|
y = find(xi => boolean)(x)
|
|
52
52
|
```
|
|
@@ -86,20 +86,20 @@ flatten([[1], [2], [3]]), // > [1, 2, 3]
|
|
|
86
86
|
|
|
87
87
|
`x` is a String or Array
|
|
88
88
|
|
|
89
|
-
`y` is the last
|
|
89
|
+
`y` is the last element of `x`
|
|
90
90
|
|
|
91
91
|
```javascript
|
|
92
92
|
first([1,2,3]) // 1
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
### forEach
|
|
96
|
-
execute a function for each
|
|
96
|
+
execute a function for each element of a collection, returning input
|
|
97
97
|
```javascript
|
|
98
98
|
y = forEach(f)(x)
|
|
99
99
|
```
|
|
100
100
|
`f` is a function
|
|
101
101
|
|
|
102
|
-
`f` is called for each
|
|
102
|
+
`f` is called for each element of `x`
|
|
103
103
|
|
|
104
104
|
`x` is an Iterable, AsyncIterable, Object, or reducer function
|
|
105
105
|
|
|
@@ -232,14 +232,14 @@ y = last(x)
|
|
|
232
232
|
|
|
233
233
|
`x` is a String or Array
|
|
234
234
|
|
|
235
|
-
`y` is the last
|
|
235
|
+
`y` is the last element of `x`
|
|
236
236
|
|
|
237
237
|
```javascript
|
|
238
238
|
last([1,2,3]) // 3
|
|
239
239
|
```
|
|
240
240
|
|
|
241
241
|
### pluck
|
|
242
|
-
create a new collection by getting a path from every
|
|
242
|
+
create a new collection by getting a path from every element of an old collection
|
|
243
243
|
```javascript
|
|
244
244
|
y = pluck(path, defaultValue)(x)
|
|
245
245
|
```
|
|
@@ -312,13 +312,13 @@ create a flattened unique array with uniques given by a binary predicate
|
|
|
312
312
|
```javascript
|
|
313
313
|
y = unionWith((a, b) => boolean)(x)
|
|
314
314
|
```
|
|
315
|
-
`a` and `b` are
|
|
315
|
+
`a` and `b` are elements of elements of `x`
|
|
316
316
|
|
|
317
317
|
`(a, b) => boolean` returns True if a and b are duplicates
|
|
318
318
|
|
|
319
319
|
`x` is an Array of Arrays of anything
|
|
320
320
|
|
|
321
|
-
`y` is a flattened Array of unique
|
|
321
|
+
`y` is a flattened Array of unique elements of elements of `x` determined by `(a, b) => boolean`
|
|
322
322
|
|
|
323
323
|
`y` is a Promise if any of the following are true
|
|
324
324
|
* `(a, b) => boolean` is asynchronous
|
package/x/append.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export = append;
|
|
|
5
5
|
* @synopsis
|
|
6
6
|
* ```coffeescript [specscript]
|
|
7
7
|
* append(
|
|
8
|
-
*
|
|
8
|
+
* element string|Array,
|
|
9
9
|
* )(value string|Array) -> string|array
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
@@ -35,4 +35,4 @@ export = append;
|
|
|
35
35
|
*
|
|
36
36
|
* @since 1.7.3
|
|
37
37
|
*/
|
|
38
|
-
declare function append(
|
|
38
|
+
declare function append(element: any): (value: any) => string | any[];
|
package/x/append.js
CHANGED
|
@@ -7,7 +7,7 @@ const isArray = require('../_internal/isArray')
|
|
|
7
7
|
* @synopsis
|
|
8
8
|
* ```coffeescript [specscript]
|
|
9
9
|
* append(
|
|
10
|
-
*
|
|
10
|
+
* element string|Array,
|
|
11
11
|
* )(value string|Array) -> string|array
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
@@ -41,20 +41,20 @@ const isArray = require('../_internal/isArray')
|
|
|
41
41
|
* @since 1.7.3
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
|
-
const append =
|
|
44
|
+
const append = element => function appendFunc(value) {
|
|
45
45
|
|
|
46
46
|
if (isArray(value)) {
|
|
47
|
-
if (isArray(
|
|
48
|
-
return [...value, ...
|
|
47
|
+
if (isArray(element)){
|
|
48
|
+
return [...value, ...element]
|
|
49
49
|
}
|
|
50
|
-
return [...value,
|
|
50
|
+
return [...value, element]
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (isString(value)){
|
|
54
|
-
if (!isString(
|
|
55
|
-
throw new TypeError(`${
|
|
54
|
+
if (!isString(element)){
|
|
55
|
+
throw new TypeError(`${element} is not a string`)
|
|
56
56
|
}
|
|
57
|
-
return `${value}${
|
|
57
|
+
return `${value}${element}`
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
throw new TypeError(`${value} is not an Array or string`)
|
package/x/defaultsDeep.js
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
const isArray = require('../_internal/isArray')
|
|
2
|
+
const curry2 = require('../_internal/curry2')
|
|
3
|
+
const __ = require('../_internal/placeholder')
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* @name arrayDefaultsDeepFromArray
|
|
5
7
|
*
|
|
6
8
|
* @synopsis
|
|
7
9
|
* ```coffeescript [specscript]
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* arrayDefaultsDeepFromArray(
|
|
11
|
+
* data Array<Array|Object|any>,
|
|
12
|
+
* defaults Array<Array|Object|any>
|
|
13
|
+
* ) -> Object
|
|
12
14
|
* ```
|
|
13
15
|
*/
|
|
14
|
-
|
|
15
|
-
const defaultArrayLength =
|
|
16
|
-
result =
|
|
16
|
+
function arrayDefaultsDeepFromArray(data, defaults) {
|
|
17
|
+
const defaultArrayLength = defaults.length,
|
|
18
|
+
result = data.slice()
|
|
17
19
|
let index = -1
|
|
18
20
|
while (++index < defaultArrayLength) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
if (isArray(
|
|
22
|
-
result[index] = arrayDefaultsDeepFromArray(
|
|
23
|
-
} else if (
|
|
24
|
-
result[index] =
|
|
25
|
-
} else if (
|
|
26
|
-
result[index] =
|
|
27
|
-
} else if (
|
|
28
|
-
result[index] = objectDefaultsDeepFromObject(
|
|
21
|
+
const element = data[index],
|
|
22
|
+
defaultElement = defaults[index]
|
|
23
|
+
if (isArray(element) && isArray(defaultElement)) {
|
|
24
|
+
result[index] = arrayDefaultsDeepFromArray(element, defaultElement)
|
|
25
|
+
} else if (element == null) {
|
|
26
|
+
result[index] = defaultElement
|
|
27
|
+
} else if (defaultElement == null) {
|
|
28
|
+
result[index] = element
|
|
29
|
+
} else if (element.constructor == Object && defaultElement.constructor == Object) {
|
|
30
|
+
result[index] = objectDefaultsDeepFromObject(element, defaultElement)
|
|
29
31
|
} else {
|
|
30
|
-
result[index] =
|
|
32
|
+
result[index] = element
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
return result
|
|
@@ -38,62 +40,89 @@ const arrayDefaultsDeepFromArray = function (array, defaultArray) {
|
|
|
38
40
|
*
|
|
39
41
|
* @synopsis
|
|
40
42
|
* ```coffeescript [specscript]
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
43
|
+
* objectDefaultsDeepFromObject(
|
|
44
|
+
* data Object<Array|Object|any>,
|
|
45
|
+
* defaults Object<Array|Object|any>
|
|
46
|
+
* ) -> Object
|
|
45
47
|
* ```
|
|
46
48
|
*/
|
|
47
|
-
|
|
48
|
-
const result = { ...
|
|
49
|
-
for (const key in
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
if (isArray(
|
|
53
|
-
result[key] = arrayDefaultsDeepFromArray(
|
|
54
|
-
} else if (
|
|
55
|
-
result[key] =
|
|
56
|
-
} else if (
|
|
57
|
-
result[key] =
|
|
58
|
-
} else if (
|
|
59
|
-
result[key] = objectDefaultsDeepFromObject(
|
|
49
|
+
function objectDefaultsDeepFromObject(data, defaults) {
|
|
50
|
+
const result = { ...data }
|
|
51
|
+
for (const key in defaults) {
|
|
52
|
+
const element = data[key],
|
|
53
|
+
defaultElement = defaults[key]
|
|
54
|
+
if (isArray(element) && isArray(defaultElement)) {
|
|
55
|
+
result[key] = arrayDefaultsDeepFromArray(element, defaultElement)
|
|
56
|
+
} else if (element == null) {
|
|
57
|
+
result[key] = defaultElement
|
|
58
|
+
} else if (defaultElement == null) {
|
|
59
|
+
result[key] = element
|
|
60
|
+
} else if (element.constructor == Object && defaultElement.constructor == Object) {
|
|
61
|
+
result[key] = objectDefaultsDeepFromObject(element, defaultElement)
|
|
60
62
|
} else {
|
|
61
|
-
result[key] =
|
|
63
|
+
result[key] = element
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
return result
|
|
65
67
|
}
|
|
66
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @name _defaultsDeep
|
|
71
|
+
*
|
|
72
|
+
* @synopsis
|
|
73
|
+
* ```coffeescript [specscript]
|
|
74
|
+
* _defaultsDeep(
|
|
75
|
+
* data Object<Array|Object|any>,
|
|
76
|
+
* defaults (Object|Array)<Array|Object|any>
|
|
77
|
+
* ) -> result Object
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
function _defaultsDeep(data, defaults) {
|
|
81
|
+
if (isArray(data) && isArray(defaults)) {
|
|
82
|
+
return arrayDefaultsDeepFromArray(data, defaults)
|
|
83
|
+
}
|
|
84
|
+
if (data == null || defaults == null) {
|
|
85
|
+
return data
|
|
86
|
+
}
|
|
87
|
+
if (data.constructor == Object && defaults.constructor == Object) {
|
|
88
|
+
return objectDefaultsDeepFromObject(data, defaults)
|
|
89
|
+
}
|
|
90
|
+
return data
|
|
91
|
+
}
|
|
92
|
+
|
|
67
93
|
/**
|
|
68
94
|
* @name defaultsDeep
|
|
69
95
|
*
|
|
70
96
|
* @synopsis
|
|
71
97
|
* ```coffeescript [specscript]
|
|
72
|
-
*
|
|
73
|
-
*
|
|
98
|
+
* data (Object|Array)<Array|Object|any>
|
|
99
|
+
* defaults (Object|Array)<Array|Object|any>
|
|
74
100
|
*
|
|
75
|
-
* defaultsDeep(
|
|
101
|
+
* defaultsDeep(data, defaults) -> result Object
|
|
102
|
+
* defaultsDeep(defaults)(data) -> result Object
|
|
76
103
|
* ```
|
|
77
104
|
*
|
|
78
105
|
* @description
|
|
79
|
-
* Deeply assign default values to an
|
|
106
|
+
* Deeply assign default values to an object or array `data` using an array or object of default values `defaults`. The keys or indices of each element of `defaults` are used to extend `data` where there is no existing value. Both `data` and `defaults` may have nested arrays or objects.
|
|
80
107
|
*
|
|
81
108
|
* ```javascript [playground]
|
|
82
109
|
* import defaultsDeep from 'https://unpkg.com/rubico/dist/x/defaultsDeep.es.js'
|
|
83
110
|
*
|
|
84
|
-
* const
|
|
111
|
+
* const user = {
|
|
112
|
+
* name: 'John',
|
|
113
|
+
* images: [{ url: 'https://placehold.co/600x400' }],
|
|
114
|
+
* }
|
|
115
|
+
*
|
|
116
|
+
* const userWithDefaults = defaultsDeep(user, {
|
|
85
117
|
* name: 'placeholder',
|
|
86
118
|
* images: [
|
|
87
|
-
* { url: 'https://
|
|
88
|
-
* { url: 'https://
|
|
89
|
-
* { url: 'https://
|
|
119
|
+
* { url: 'https://placehold.co/150' },
|
|
120
|
+
* { url: 'https://placehold.co/150' },
|
|
121
|
+
* { url: 'https://placehold.co/150' },
|
|
90
122
|
* ],
|
|
91
123
|
* })
|
|
92
124
|
*
|
|
93
|
-
* console.log(
|
|
94
|
-
* name: 'John',
|
|
95
|
-
* images: [{ url: 'https://via.placeholder.com/150/0000FF/808080%20?Text=Digital.com' }],
|
|
96
|
-
* }))
|
|
125
|
+
* console.log(userWithDefaults)
|
|
97
126
|
* // {
|
|
98
127
|
* // name: 'John',
|
|
99
128
|
* // images: [
|
|
@@ -104,22 +133,30 @@ const objectDefaultsDeepFromObject = function (object, defaultObject) {
|
|
|
104
133
|
* // }
|
|
105
134
|
* ```
|
|
106
135
|
*
|
|
136
|
+
* The `defaults` array or object may be provided to `defaultsDeep` without `data` to create a lazy version of `defaultsDeep` that accepts `data` as a single argument. This "lazy" API can be used for function pipelines and function compositions.
|
|
137
|
+
*
|
|
138
|
+
* ```javascript [playground]
|
|
139
|
+
* pipe({ a: 1 }, [
|
|
140
|
+
* defaultsDeep({ b: 2, c: 3, g: [1, 2, 3] }),
|
|
141
|
+
* console.log, // { a: 1, b: 2, c: 3, g: [1, 2, 3] }
|
|
142
|
+
* ])
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
107
145
|
* See also:
|
|
146
|
+
* * [pipe](/docs/pipe)
|
|
147
|
+
* * [compose](/docs/compose)
|
|
108
148
|
* * [callProp](/docs/callProp)
|
|
109
149
|
* * [differenceWith](/docs/differenceWith)
|
|
110
150
|
*
|
|
111
151
|
*/
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
if (value == null || defaultCollection == null) {
|
|
117
|
-
return value
|
|
152
|
+
function defaultsDeep(...args) {
|
|
153
|
+
if (args.length == 1) {
|
|
154
|
+
return curry2(_defaultsDeep, __, args[0])
|
|
118
155
|
}
|
|
119
|
-
if (
|
|
120
|
-
return
|
|
156
|
+
if (args.length == 2) {
|
|
157
|
+
return _defaultsDeep(...args)
|
|
121
158
|
}
|
|
122
|
-
|
|
159
|
+
throw new TypeError('Invalid number of arguments')
|
|
123
160
|
}
|
|
124
161
|
|
|
125
162
|
module.exports = defaultsDeep
|
package/x/defaultsDeep.test.js
CHANGED
|
@@ -2,6 +2,29 @@ const assert = require('assert')
|
|
|
2
2
|
const defaultsDeep = require('./defaultsDeep')
|
|
3
3
|
|
|
4
4
|
describe('defaultsDeep', () => {
|
|
5
|
+
it('eager API', async () => {
|
|
6
|
+
assert.deepEqual(
|
|
7
|
+
defaultsDeep([3], [1, 2, 3]),
|
|
8
|
+
[3, 2, 3],
|
|
9
|
+
)
|
|
10
|
+
assert.deepEqual(
|
|
11
|
+
defaultsDeep([[]], [[1], 2, 3]),
|
|
12
|
+
[[1], 2, 3],
|
|
13
|
+
)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('Invalid number of arguments', async () => {
|
|
17
|
+
assert.throws(
|
|
18
|
+
() => defaultsDeep(),
|
|
19
|
+
new TypeError('Invalid number of arguments'),
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
assert.throws(
|
|
23
|
+
() => defaultsDeep(1, 2, 3),
|
|
24
|
+
new TypeError('Invalid number of arguments'),
|
|
25
|
+
)
|
|
26
|
+
})
|
|
27
|
+
|
|
5
28
|
it('default array', async () => {
|
|
6
29
|
assert.deepEqual(
|
|
7
30
|
defaultsDeep([1, 2, 3])([3]),
|
|
@@ -97,7 +120,7 @@ describe('defaultsDeep', () => {
|
|
|
97
120
|
{ obj: { a: '1' } },
|
|
98
121
|
)
|
|
99
122
|
})
|
|
100
|
-
it('nullish default
|
|
123
|
+
it('nullish default element should use current element', async () => {
|
|
101
124
|
assert.deepEqual(
|
|
102
125
|
defaultsDeep([null, 1, 2, 3, 4])([0, 1, 2]),
|
|
103
126
|
[0, 1, 2, 3, 4],
|