rubico 2.11.0 → 2.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -20
- package/Transducer.js +37 -58
- package/__.js +3 -3
- package/always.js +4 -4
- package/and.js +34 -26
- package/assign.js +2 -2
- package/compose.js +1 -0
- package/curry.js +48 -28
- package/dist/Transducer.es.js +1 -1
- package/dist/Transducer.es.min.js +1 -1
- package/dist/Transducer.js +1 -1
- package/dist/Transducer.min.js +1 -1
- package/dist/Transducer.mjs +1 -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 +113 -19
- package/dist/filter.es.min.js +2 -2
- package/dist/filter.js +113 -19
- package/dist/filter.min.js +2 -2
- package/dist/filter.mjs +113 -19
- 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 -19
- package/dist/rubico.es.min.js +2 -2
- package/dist/rubico.global.js +57 -19
- package/dist/rubico.global.min.js +2 -2
- package/dist/rubico.js +57 -19
- package/dist/rubico.min.js +2 -2
- package/dist/rubico.mjs +57 -19
- 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 +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 +1 -1
- package/dist/transform.es.min.js +1 -1
- package/dist/transform.js +1 -1
- package/dist/transform.min.js +1 -1
- package/dist/transform.mjs +1 -1
- 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 +113 -19
- package/dist/x/filterOut.es.min.js +2 -2
- package/dist/x/filterOut.js +113 -19
- package/dist/x/filterOut.min.js +2 -2
- package/dist/x/filterOut.mjs +113 -19
- 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 +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 +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/eq.js +29 -30
- package/es.js +57 -19
- package/every.js +14 -20
- package/filter.js +38 -75
- package/flatMap.js +13 -13
- package/forEach.js +8 -8
- package/get.js +3 -3
- package/gt.js +18 -25
- package/gte.js +22 -29
- package/index.js +57 -19
- package/lt.js +33 -31
- package/lte.js +24 -31
- package/map.js +32 -35
- package/not.js +12 -17
- package/or.js +34 -26
- package/package.json +1 -1
- package/reduce.js +60 -67
- package/some.js +11 -34
- package/switchCase.js +3 -3
- package/thunkify.js +42 -12
- package/transform.js +57 -56
package/or.js
CHANGED
|
@@ -97,37 +97,28 @@ const areAnyPredicatesTruthy = function (args, predicates) {
|
|
|
97
97
|
*
|
|
98
98
|
* @synopsis
|
|
99
99
|
* ```coffeescript [specscript]
|
|
100
|
-
*
|
|
101
|
-
* argsOrPromises Array<Promise|any>
|
|
100
|
+
* type SyncOrAsyncPredicate = (...arguments)=>Promise|boolean|any
|
|
102
101
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* predicatesOrValues Array<SyncOrAsyncPredicate|boolean|any>
|
|
106
|
-
*
|
|
107
|
-
* or(values Array<boolean|any>) -> result boolean
|
|
108
|
-
* or(...argsOrPromises, predicatesOrValues) -> Promise|boolean
|
|
109
|
-
* or(predicatesOrValues)(...args) -> Promise|boolean
|
|
102
|
+
* or(values Array<boolean|any>) -> testResult boolean
|
|
103
|
+
* or(...arguments, predicatesOrValues Array<SyncOrAsyncPredicate|boolean|any>) -> testResult Promise|boolean
|
|
104
|
+
* or(predicatesOrValues Array<SyncOrAsyncPredicate|boolean|any>)(...arguments) -> testResult Promise|boolean
|
|
110
105
|
* ```
|
|
111
106
|
*
|
|
112
107
|
* @description
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* If provided an array of boolean values, `or` returns true if any boolean values are truthy.
|
|
108
|
+
* Logical operator. Tests an array of predicate functions, promises, or values, returning true if any predicate tests true or any value is truthy.
|
|
116
109
|
*
|
|
117
110
|
* ```javascript [playground]
|
|
118
|
-
* const
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* const condition = or([
|
|
123
|
-
* oneIsLessThanZero,
|
|
124
|
-
* oneIsGreaterThanTwo,
|
|
125
|
-
* threeIsNotEqualToThree
|
|
111
|
+
* const isOddOrGreaterThan3 = or([
|
|
112
|
+
* n => n % 2 == 1,
|
|
113
|
+
* n => n > 3,
|
|
126
114
|
* ])
|
|
127
|
-
*
|
|
115
|
+
*
|
|
116
|
+
* console.log(isOddOrGreaterThan3(2))
|
|
117
|
+
* console.log(isOddOrGreaterThan3(3))
|
|
118
|
+
* console.log(isOddOrGreaterThan3(6))
|
|
128
119
|
* ```
|
|
129
120
|
*
|
|
130
|
-
* If
|
|
121
|
+
* If the array contains predicate functions, `or` returns an aggregate predicate function that returns true if some predicate function test true. If any predicate function is asynchronous, the aggregate predicate function is asynchronous.
|
|
131
122
|
*
|
|
132
123
|
* ```javascript [playground]
|
|
133
124
|
* const isOdd = number => number % 2 == 1
|
|
@@ -141,17 +132,34 @@ const areAnyPredicatesTruthy = function (args, predicates) {
|
|
|
141
132
|
* asyncIsGreaterThan3,
|
|
142
133
|
* ])
|
|
143
134
|
*
|
|
144
|
-
* const
|
|
145
|
-
*
|
|
135
|
+
* const booleanResult = await aggregatePredicate(2)
|
|
136
|
+
*
|
|
137
|
+
* console.log(booleanResult)
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* If the array contains only values, `or` returns a boolean value.
|
|
141
|
+
*
|
|
142
|
+
* ```javascript [playground]
|
|
143
|
+
* const oneIsLessThanZero = 1 < 0
|
|
144
|
+
* const oneIsGreaterThanTwo = 1 > 2
|
|
145
|
+
* const threeIsNotEqualToThree = 3 !== 3
|
|
146
|
+
*
|
|
147
|
+
* const booleanResult = or([
|
|
148
|
+
* oneIsLessThanZero,
|
|
149
|
+
* oneIsGreaterThanTwo,
|
|
150
|
+
* threeIsNotEqualToThree
|
|
151
|
+
* ])
|
|
152
|
+
*
|
|
153
|
+
* console.log(booleanResult)
|
|
146
154
|
* ```
|
|
147
155
|
*
|
|
148
|
-
* Any promises
|
|
156
|
+
* Any promises in the array are resolved for their values before further execution.
|
|
149
157
|
*
|
|
150
158
|
* ```javascript [playground]
|
|
151
159
|
* or(Promise.resolve('aaa'), [
|
|
152
160
|
* s => s.startsWith('b'),
|
|
153
161
|
* s => s.endsWith('a'),
|
|
154
|
-
* ]).then(console.log)
|
|
162
|
+
* ]).then(console.log)
|
|
155
163
|
* ```
|
|
156
164
|
*
|
|
157
165
|
* See also:
|
package/package.json
CHANGED
package/reduce.js
CHANGED
|
@@ -25,22 +25,42 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
25
25
|
*
|
|
26
26
|
* type SyncOrAsyncReducer = (
|
|
27
27
|
* accumulator any,
|
|
28
|
-
*
|
|
28
|
+
* item any,
|
|
29
29
|
* indexOrKey number|string|any,
|
|
30
30
|
* foldable Foldable
|
|
31
31
|
* )=>(nextAccumulator Promise|any)
|
|
32
32
|
*
|
|
33
33
|
* type UnarySyncOrAsyncResolver = any=>Promise|any
|
|
34
34
|
*
|
|
35
|
-
* reducer SyncOrAsyncReducer
|
|
36
|
-
*
|
|
35
|
+
* reduce(foldable Promise|Foldable, reducer SyncOrAsyncReducer) -> accumulator Promise|any
|
|
36
|
+
* reduce(foldable Promise|Foldable, reducer SyncOrAsyncReducer, initialValue Promise|any) -> accumulator Promise|any
|
|
37
|
+
* reduce(foldable Promise|Foldable, reducer SyncOrAsyncReducer, initialResolver UnarySyncOrAsyncResolver) -> accumulator Promise|any
|
|
37
38
|
*
|
|
38
|
-
* reduce(foldable
|
|
39
|
-
* reduce(reducer,
|
|
39
|
+
* reduce(reducer SyncOrAsyncReducer)(foldable Foldable) -> accumulator Promise|any
|
|
40
|
+
* reduce(reducer SyncOrAsyncReducer, initialValue Promise|any)(foldable Foldable) -> accumulator Promise|any
|
|
41
|
+
* reduce(reducer SyncOrAsyncReducer, initialResolver UnarySyncOrAsyncResolver)(foldable Foldable) -> accumulator Promise|any
|
|
40
42
|
* ```
|
|
41
43
|
*
|
|
42
44
|
* @description
|
|
43
|
-
* Reduces a foldable to
|
|
45
|
+
* Reduces a foldable to an accumulated value.
|
|
46
|
+
*
|
|
47
|
+
* ```javascript [playground]
|
|
48
|
+
* const max = (a, b) => a > b ? a : b
|
|
49
|
+
*
|
|
50
|
+
* const result = reduce([1, 3, 5, 4, 2], max)
|
|
51
|
+
*
|
|
52
|
+
* console.log(result)
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* `reduce` executes a reducer function for each item of a foldable in order. If an initial value is provided, `reduce` starts iterating from the first item of the foldable. If no initial value is provided, `reduce` uses the first item of the foldable as the initial value and starts iterating from the second item of the foldable.
|
|
56
|
+
*
|
|
57
|
+
* ```javascript [playground]
|
|
58
|
+
* const add = (a, b) => a + b
|
|
59
|
+
*
|
|
60
|
+
* const result = reduce([1, 2, 3, 4, 5], add, 10)
|
|
61
|
+
*
|
|
62
|
+
* console.log(result)
|
|
63
|
+
* ```
|
|
44
64
|
*
|
|
45
65
|
* The following data types are considered to be foldables:
|
|
46
66
|
* * `array`
|
|
@@ -51,11 +71,11 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
51
71
|
* * `object with .reduce method`
|
|
52
72
|
* * `object`
|
|
53
73
|
*
|
|
54
|
-
* The reducing operation is
|
|
74
|
+
* The reducing operation is expressed by the reducer function and optional initial value, which defines a transformation between an accumulator and a given item of the foldable.
|
|
55
75
|
*
|
|
56
76
|
* ```javascript
|
|
57
|
-
* const reducer = function (accumulator,
|
|
58
|
-
* // nextAccumulator is the result of some operation between accumulator and
|
|
77
|
+
* const reducer = function (accumulator, item) {
|
|
78
|
+
* // nextAccumulator is the result of some operation between accumulator and item
|
|
59
79
|
* // and becomes the accumulator for the next iteration and invocation of the reducer
|
|
60
80
|
* return nextAccumulator
|
|
61
81
|
* }
|
|
@@ -67,7 +87,7 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
67
87
|
* ```coffeescript [specscript]
|
|
68
88
|
* reducer(
|
|
69
89
|
* accumulator any,
|
|
70
|
-
*
|
|
90
|
+
* item any,
|
|
71
91
|
* index number,
|
|
72
92
|
* fold Array
|
|
73
93
|
* ) -> nextAccumulator Promise|any
|
|
@@ -77,7 +97,7 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
77
97
|
* ```coffeescript [specscript]
|
|
78
98
|
* reducer(
|
|
79
99
|
* accumulator any,
|
|
80
|
-
*
|
|
100
|
+
* item any
|
|
81
101
|
* ) -> nextAccumulator Promise|any
|
|
82
102
|
* ```
|
|
83
103
|
*
|
|
@@ -85,7 +105,7 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
85
105
|
* ```coffeescript [specscript]
|
|
86
106
|
* reducer(
|
|
87
107
|
* accumulator any,
|
|
88
|
-
*
|
|
108
|
+
* item any,
|
|
89
109
|
* key any,
|
|
90
110
|
* fold Map
|
|
91
111
|
* ) -> nextAccumulator Promise|any
|
|
@@ -95,7 +115,7 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
95
115
|
* ```coffeescript [specscript]
|
|
96
116
|
* reducer(
|
|
97
117
|
* accumulator any,
|
|
98
|
-
*
|
|
118
|
+
* item any
|
|
99
119
|
* ) -> nextAccumulator Promise|any
|
|
100
120
|
* ```
|
|
101
121
|
*
|
|
@@ -103,47 +123,30 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
103
123
|
* ```coffeescript [specscript]
|
|
104
124
|
* reducer(
|
|
105
125
|
* accumulator any,
|
|
106
|
-
*
|
|
126
|
+
* item any
|
|
107
127
|
* ) -> nextAccumulator Promise|any
|
|
108
128
|
* ```
|
|
109
129
|
*
|
|
110
|
-
* If the foldable is an object with a `.reduce` method, the reducer function signature is defined externally.
|
|
111
|
-
*
|
|
112
130
|
* If the foldable is a plain object:
|
|
113
131
|
* ```coffeescript [specscript]
|
|
114
132
|
* reducer(
|
|
115
133
|
* accumulator any,
|
|
116
|
-
*
|
|
134
|
+
* item any,
|
|
117
135
|
* key string,
|
|
118
136
|
* fold Object
|
|
119
137
|
* ) -> nextAccumulator Promise|any
|
|
120
138
|
* ```
|
|
121
139
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* ```javascript [playground]
|
|
125
|
-
* const max = (a, b) => a > b ? a : b
|
|
126
|
-
*
|
|
127
|
-
* const result = reduce([1, 3, 5, 4, 2], max)
|
|
128
|
-
* console.log(result) // 5
|
|
129
|
-
* ```
|
|
130
|
-
*
|
|
131
|
-
* If an initial value is provided, the accumulator starts as the initial value rather than the first element of the foldable.
|
|
132
|
-
*
|
|
133
|
-
* ```javascript [playground]
|
|
134
|
-
* const add = (a, b) => a + b
|
|
135
|
-
*
|
|
136
|
-
* const result = reduce([1, 2, 3, 4, 5], add, 0)
|
|
137
|
-
* console.log(result) // 15
|
|
138
|
-
* ```
|
|
140
|
+
* If the foldable is an object with a `.reduce` method, the reducer function signature is defined externally.
|
|
139
141
|
*
|
|
140
142
|
* If the reducer is asynchronous, all promises created by the reducer are resolved before continuing with the reducing operation.
|
|
141
143
|
*
|
|
142
144
|
* ```javascript [playground]
|
|
143
145
|
* const asyncAdd = async (a, b) => a + b
|
|
144
146
|
*
|
|
145
|
-
* const
|
|
146
|
-
*
|
|
147
|
+
* const result = await reduce([1, 2, 3, 4, 5], asyncAdd, 0)
|
|
148
|
+
*
|
|
149
|
+
* console.log(result)
|
|
147
150
|
* ```
|
|
148
151
|
*
|
|
149
152
|
* If the initialization parameter is a function, it is treated as a resolver of the initial value and called with the foldable.
|
|
@@ -151,63 +154,53 @@ const _reduce = function (collection, reducer, initial) {
|
|
|
151
154
|
* ```javascript [playground]
|
|
152
155
|
* const concatSquares = (array, value) => array.concat(value ** 2)
|
|
153
156
|
*
|
|
154
|
-
* const contrivedInitializer = array => [`initial length ${array.length}`]
|
|
155
|
-
*
|
|
156
157
|
* const array = [1, 2, 3, 4, 5]
|
|
157
158
|
*
|
|
158
|
-
*
|
|
159
|
-
* // ['initial length 5', 1, 4, 9, 16, 25]
|
|
160
|
-
* ```
|
|
161
|
-
*
|
|
162
|
-
* For objects, `reduce` iterates over just the values.
|
|
163
|
-
*
|
|
164
|
-
* ```javascript [playground]
|
|
165
|
-
* const add = (a, b) => a + b
|
|
166
|
-
*
|
|
167
|
-
* const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
|
159
|
+
* const result = reduce(array, concatSquares, () => [])
|
|
168
160
|
*
|
|
169
|
-
*
|
|
170
|
-
* console.log(result) // 15
|
|
161
|
+
* console.log(result)
|
|
171
162
|
* ```
|
|
172
163
|
*
|
|
173
|
-
*
|
|
164
|
+
* `reduce` iterates over just the values of objects and maps.
|
|
174
165
|
*
|
|
175
166
|
* ```javascript [playground]
|
|
176
167
|
* const add = (a, b) => a + b
|
|
177
168
|
*
|
|
178
|
-
* const
|
|
169
|
+
* const object = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
|
170
|
+
* const map = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
|
|
179
171
|
*
|
|
180
|
-
* const
|
|
181
|
-
*
|
|
172
|
+
* const objectResult = reduce(object, add)
|
|
173
|
+
* const mapResult = reduce(map, add)
|
|
174
|
+
*
|
|
175
|
+
* console.log(objectResult)
|
|
176
|
+
* console.log(mapResult)
|
|
182
177
|
* ```
|
|
183
178
|
*
|
|
184
|
-
* `reduce`
|
|
179
|
+
* `reduce` reduces async generators.
|
|
185
180
|
*
|
|
186
181
|
* ```javascript [playground]
|
|
187
|
-
* const
|
|
182
|
+
* const add = (a, b) => a + b
|
|
188
183
|
*
|
|
189
|
-
* const
|
|
184
|
+
* const generateAsyncNumbers = async function* () {
|
|
190
185
|
* yield 1; yield 2; yield 3; yield 4; yield 5
|
|
191
186
|
* }
|
|
192
187
|
*
|
|
193
|
-
* reduce(
|
|
188
|
+
* const result = await reduce(generateAsyncNumbers(), add)
|
|
189
|
+
*
|
|
190
|
+
* console.log(result)
|
|
194
191
|
* ```
|
|
195
192
|
*
|
|
196
|
-
*
|
|
193
|
+
* If the foldable or initial value is a promise, it is resolved for its value before further execution for the eager interface only.
|
|
197
194
|
*
|
|
198
195
|
* ```javascript [playground]
|
|
199
196
|
* const add = (a, b) => a + b
|
|
200
197
|
*
|
|
201
|
-
* reduce(Promise.resolve([1, 2, 3, 4, 5]), add, 0)
|
|
202
|
-
* ```
|
|
203
|
-
*
|
|
204
|
-
* Any promises passed for the initial value are also resolved before further execution.
|
|
198
|
+
* const resultWithPromiseFoldable = await reduce(Promise.resolve([1, 2, 3, 4, 5]), add, 0)
|
|
205
199
|
*
|
|
206
|
-
*
|
|
207
|
-
* const add = (a, b) => a + b
|
|
200
|
+
* const resultWithPromiseInitialValue = await reduce([1, 2, 3, 4, 5], add, Promise.resolve(0))
|
|
208
201
|
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
202
|
+
* console.log(resultWithPromiseFoldable)
|
|
203
|
+
* console.log(resultWithPromiseInitialValue)
|
|
211
204
|
* ```
|
|
212
205
|
*
|
|
213
206
|
* See also:
|
package/some.js
CHANGED
|
@@ -45,19 +45,21 @@ const _some = function (collection, predicate) {
|
|
|
45
45
|
*
|
|
46
46
|
* predicate UnarySyncOrAsyncPredicate
|
|
47
47
|
*
|
|
48
|
-
* some(foldable Foldable, predicate) -> Promise|boolean
|
|
49
|
-
* some(predicate)(foldable Foldable) -> Promise|boolean
|
|
48
|
+
* some(foldable Promise|Foldable, predicate) -> testResult Promise|boolean
|
|
49
|
+
* some(predicate)(foldable Foldable) -> testResult Promise|boolean
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
52
|
* @description
|
|
53
|
-
*
|
|
53
|
+
* Tests a predicate concurrently across all items of a foldable. Returns true if any item tests true by the predicate.
|
|
54
54
|
*
|
|
55
55
|
* ```javascript [playground]
|
|
56
56
|
* const isOdd = number => number % 2 == 1
|
|
57
57
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
58
|
+
* const array = [1, 2, 3, 4, 5]
|
|
59
|
+
*
|
|
60
|
+
* const arrayHasOddNumbers = some(array, isOdd)
|
|
61
|
+
*
|
|
62
|
+
* console.log(arrayHasOddNumbers)
|
|
61
63
|
* ```
|
|
62
64
|
*
|
|
63
65
|
* The following data types are considered to be foldables:
|
|
@@ -69,44 +71,19 @@ const _some = function (collection, predicate) {
|
|
|
69
71
|
* * `object with .reduce method`
|
|
70
72
|
* * `object`
|
|
71
73
|
*
|
|
72
|
-
* `some` works for async generators.
|
|
73
|
-
*
|
|
74
|
-
* ```javascript [playground]
|
|
75
|
-
* const toTodosUrl = id => 'https://jsonplaceholder.typicode.com/todos/' + id
|
|
76
|
-
*
|
|
77
|
-
* const fetchedToJson = fetched => fetched.json()
|
|
78
|
-
*
|
|
79
|
-
* const fetchTodo = pipe([
|
|
80
|
-
* toTodosUrl,
|
|
81
|
-
* fetch,
|
|
82
|
-
* fetchedToJson,
|
|
83
|
-
* ])
|
|
84
|
-
*
|
|
85
|
-
* const todoIDsGenerator = async function* () {
|
|
86
|
-
* yield 1; yield 2; yield 3; yield 4; yield 5
|
|
87
|
-
* }
|
|
88
|
-
*
|
|
89
|
-
* const promise = some(todoIDsGenerator(), async id => {
|
|
90
|
-
* const todo = await fetchTodo(id)
|
|
91
|
-
* return todo.title.startsWith('fugiat')
|
|
92
|
-
* })
|
|
93
|
-
*
|
|
94
|
-
* promise.then(console.log) // true
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
74
|
* `some` supports a lazy interface for composability.
|
|
98
75
|
*
|
|
99
76
|
* ```javascript [playground]
|
|
100
77
|
* pipe([1, 2, 3], [
|
|
101
78
|
* some(number => number < 5),
|
|
102
|
-
* console.log,
|
|
79
|
+
* console.log,
|
|
103
80
|
* ])
|
|
104
81
|
* ```
|
|
105
82
|
*
|
|
106
|
-
*
|
|
83
|
+
* If the foldable is a promise, it is resolved for its value before further execution for the eager interface only.
|
|
107
84
|
*
|
|
108
85
|
* ```javascript [playground]
|
|
109
|
-
* some(Promise.resolve([1, 2, 3, 4, 5]), n => n > 6).then(console.log)
|
|
86
|
+
* some(Promise.resolve([1, 2, 3, 4, 5]), n => n > 6).then(console.log)
|
|
110
87
|
* ```
|
|
111
88
|
*
|
|
112
89
|
* See also:
|
package/switchCase.js
CHANGED
|
@@ -44,7 +44,7 @@ const curryArgs3 = require('./_internal/curryArgs3')
|
|
|
44
44
|
* const fruitsGuesser = switchCase([
|
|
45
45
|
* fruit => fruit.color == 'yellow',
|
|
46
46
|
* fruit => fruit.name + ' is possibly a banana',
|
|
47
|
-
* fruit => fruit.name + ' is
|
|
47
|
+
* fruit => fruit.name + ' is possibly not a banana',
|
|
48
48
|
* ])
|
|
49
49
|
*
|
|
50
50
|
* const guess1 = fruitsGuesser({ name: 'plantain', color: 'yellow' })
|
|
@@ -91,13 +91,13 @@ const curryArgs3 = require('./_internal/curryArgs3')
|
|
|
91
91
|
* (a, b, c) => console.log(`${a} + ${b} + ${c} !== 6`),
|
|
92
92
|
* ])
|
|
93
93
|
*
|
|
94
|
-
* const
|
|
94
|
+
* const result = await switchCase(true, [
|
|
95
95
|
* bool => bool,
|
|
96
96
|
* Promise.resolve(1),
|
|
97
97
|
* Promise.resolve(2),
|
|
98
98
|
* ])
|
|
99
99
|
*
|
|
100
|
-
*
|
|
100
|
+
* console.log(result)
|
|
101
101
|
* ```
|
|
102
102
|
*
|
|
103
103
|
* See also:
|
package/thunkify.js
CHANGED
|
@@ -23,20 +23,28 @@ function _thunkifyArgs(func, context, args) {
|
|
|
23
23
|
*
|
|
24
24
|
* @synopsis
|
|
25
25
|
* ```coffeescript [specscript]
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* thunkify(func function, ...args) -> thunk ()=>func(...args)
|
|
26
|
+
* thunkify(func function, ...arguments) -> thunk function
|
|
29
27
|
* ```
|
|
30
28
|
*
|
|
31
29
|
* @description
|
|
32
|
-
* Creates a thunk from a function and arguments. A thunk takes no arguments, and when called, executes the
|
|
30
|
+
* Creates a thunk function from a function and arguments. A thunk function takes no arguments, and when called, executes the function and arguments. The function is said to be "thunkified".
|
|
33
31
|
*
|
|
34
32
|
* ```javascript [playground]
|
|
35
33
|
* const add = (a, b) => a + b
|
|
36
34
|
*
|
|
37
35
|
* const thunkAdd12 = thunkify(add, 1, 2)
|
|
38
36
|
*
|
|
39
|
-
* console.log(thunkAdd12())
|
|
37
|
+
* console.log(thunkAdd12())
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* Any promises in `arguments` are resolved for their values during thunk creation.
|
|
41
|
+
*
|
|
42
|
+
* ```javascript [playground]
|
|
43
|
+
* const add = (a, b) => a + b
|
|
44
|
+
*
|
|
45
|
+
* const thunkAdd12 = await thunkify(add, Promise.resolve(1), 2)
|
|
46
|
+
*
|
|
47
|
+
* console.log(thunkAdd12())
|
|
40
48
|
* ```
|
|
41
49
|
*
|
|
42
50
|
* See also:
|
|
@@ -60,13 +68,35 @@ const thunkify = function thunkify(func, ...args) {
|
|
|
60
68
|
*
|
|
61
69
|
* @synopsis
|
|
62
70
|
* ```coffeescript [specscript]
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* thunkify.call(func function, context object, ...args) -> thunk ()=>func(...args)
|
|
71
|
+
* thunkify.call(func function, context object, ...arguments) -> thunk function
|
|
66
72
|
* ```
|
|
67
73
|
*
|
|
68
74
|
* @description
|
|
69
|
-
* Creates a thunk that calls a function with the specified context and arguments.
|
|
75
|
+
* Creates a thunk function that calls a function with the specified context and arguments.
|
|
76
|
+
*
|
|
77
|
+
* ```javascript [playground]
|
|
78
|
+
* class Point {
|
|
79
|
+
* constructor(x, y) {
|
|
80
|
+
* this.x = x
|
|
81
|
+
* this.y = y
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* distanceTo(point) {
|
|
85
|
+
* const x2 = (point.x - this.x) ** 2
|
|
86
|
+
* const y2 = (point.y - this.y) ** 2
|
|
87
|
+
* return (x2 + y2) ** 0.5
|
|
88
|
+
* }
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* const point0 = new Point(0, 0)
|
|
92
|
+
* const point1 = new Point(3, 4)
|
|
93
|
+
*
|
|
94
|
+
* const thunk = thunkify.call(point0.distanceTo, point0, point1)
|
|
95
|
+
*
|
|
96
|
+
* console.log(thunk())
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* Any promises in `arguments` are resolved for their values during thunk creation.
|
|
70
100
|
*
|
|
71
101
|
* ```javascript [playground]
|
|
72
102
|
* class Point {
|
|
@@ -75,7 +105,7 @@ const thunkify = function thunkify(func, ...args) {
|
|
|
75
105
|
* this.y = y
|
|
76
106
|
* }
|
|
77
107
|
*
|
|
78
|
-
* distanceTo() {
|
|
108
|
+
* distanceTo(point) {
|
|
79
109
|
* const x2 = (point.x - this.x) ** 2
|
|
80
110
|
* const y2 = (point.y - this.y) ** 2
|
|
81
111
|
* return (x2 + y2) ** 0.5
|
|
@@ -83,9 +113,9 @@ const thunkify = function thunkify(func, ...args) {
|
|
|
83
113
|
* }
|
|
84
114
|
*
|
|
85
115
|
* const point0 = new Point(0, 0)
|
|
86
|
-
* const
|
|
116
|
+
* const point1 = new Point(3, 4)
|
|
87
117
|
*
|
|
88
|
-
* const thunk = thunkify.call(point0.distanceTo, point0,
|
|
118
|
+
* const thunk = await thunkify.call(point0.distanceTo, point0, Promise.resolve(point1))
|
|
89
119
|
*
|
|
90
120
|
* console.log(thunk())
|
|
91
121
|
* ```
|