rubico 2.6.5 → 2.6.6
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/dist/Transducer.es.js +2 -2
- package/dist/Transducer.es.min.js +2 -2
- package/dist/Transducer.js +2 -2
- package/dist/Transducer.min.js +2 -2
- package/dist/Transducer.mjs +2 -2
- package/dist/__.es.js +2 -2
- package/dist/__.es.min.js +2 -2
- package/dist/__.js +2 -2
- package/dist/__.min.js +2 -2
- package/dist/__.mjs +2 -2
- package/dist/all.es.js +2 -22
- package/dist/all.es.min.js +2 -2
- package/dist/all.js +2 -22
- package/dist/all.min.js +2 -2
- package/dist/all.mjs +2 -22
- package/dist/always.es.js +2 -2
- package/dist/always.es.min.js +2 -2
- package/dist/always.js +2 -2
- package/dist/always.min.js +2 -2
- package/dist/always.mjs +2 -2
- package/dist/and.es.js +2 -2
- package/dist/and.es.min.js +2 -2
- package/dist/and.js +2 -2
- package/dist/and.min.js +2 -2
- package/dist/and.mjs +2 -2
- package/dist/assign.es.js +2 -2
- package/dist/assign.es.min.js +2 -2
- package/dist/assign.js +2 -2
- package/dist/assign.min.js +2 -2
- package/dist/assign.mjs +2 -2
- package/dist/compose.es.js +2 -2
- package/dist/compose.es.min.js +2 -2
- package/dist/compose.js +2 -2
- package/dist/compose.min.js +2 -2
- package/dist/compose.mjs +2 -2
- package/dist/curry.es.js +2 -2
- package/dist/curry.es.min.js +2 -2
- package/dist/curry.js +2 -2
- package/dist/curry.min.js +2 -2
- package/dist/curry.mjs +2 -2
- package/dist/eq.es.js +2 -2
- package/dist/eq.es.min.js +2 -2
- package/dist/eq.js +2 -2
- package/dist/eq.min.js +2 -2
- package/dist/eq.mjs +2 -2
- package/dist/every.es.js +2 -2
- package/dist/every.es.min.js +2 -2
- package/dist/every.js +2 -2
- package/dist/every.min.js +2 -2
- package/dist/every.mjs +2 -2
- package/dist/filter.es.js +5 -3
- package/dist/filter.es.min.js +3 -3
- package/dist/filter.js +5 -3
- package/dist/filter.min.js +3 -3
- package/dist/filter.mjs +5 -3
- package/dist/flatMap.es.js +2 -2
- package/dist/flatMap.es.min.js +2 -2
- package/dist/flatMap.js +2 -2
- package/dist/flatMap.min.js +2 -2
- package/dist/flatMap.mjs +2 -2
- package/dist/forEach.es.js +2 -2
- package/dist/forEach.es.min.js +2 -2
- package/dist/forEach.js +2 -2
- package/dist/forEach.min.js +2 -2
- package/dist/forEach.mjs +2 -2
- package/dist/get.es.js +2 -2
- package/dist/get.es.min.js +2 -2
- package/dist/get.js +2 -2
- package/dist/get.min.js +2 -2
- package/dist/get.mjs +2 -2
- package/dist/gt.es.js +2 -2
- package/dist/gt.es.min.js +2 -2
- package/dist/gt.js +2 -2
- package/dist/gt.min.js +2 -2
- package/dist/gt.mjs +2 -2
- package/dist/gte.es.js +2 -2
- package/dist/gte.es.min.js +2 -2
- package/dist/gte.js +2 -2
- package/dist/gte.min.js +2 -2
- package/dist/gte.mjs +2 -2
- package/dist/lt.es.js +2 -2
- package/dist/lt.es.min.js +2 -2
- package/dist/lt.js +2 -2
- package/dist/lt.min.js +2 -2
- package/dist/lt.mjs +2 -2
- package/dist/lte.es.js +2 -2
- package/dist/lte.es.min.js +2 -2
- package/dist/lte.js +2 -2
- package/dist/lte.min.js +2 -2
- package/dist/lte.mjs +2 -2
- package/dist/map.es.js +31 -31
- package/dist/map.es.min.js +3 -3
- package/dist/map.js +31 -31
- package/dist/map.min.js +3 -3
- package/dist/map.mjs +31 -31
- package/dist/not.es.js +2 -2
- package/dist/not.es.min.js +2 -2
- package/dist/not.js +2 -2
- package/dist/not.min.js +2 -2
- package/dist/not.mjs +2 -2
- package/dist/omit.es.js +2 -2
- package/dist/omit.es.min.js +2 -2
- package/dist/omit.js +2 -2
- package/dist/omit.min.js +2 -2
- package/dist/omit.mjs +2 -2
- package/dist/or.es.js +2 -2
- package/dist/or.es.min.js +2 -2
- package/dist/or.js +2 -2
- package/dist/or.min.js +2 -2
- package/dist/or.mjs +2 -2
- package/dist/pick.es.js +2 -2
- package/dist/pick.es.min.js +2 -2
- package/dist/pick.js +2 -2
- package/dist/pick.min.js +2 -2
- package/dist/pick.mjs +2 -2
- package/dist/pipe.es.js +2 -2
- package/dist/pipe.es.min.js +2 -2
- package/dist/pipe.js +2 -2
- package/dist/pipe.min.js +2 -2
- package/dist/pipe.mjs +2 -2
- package/dist/reduce.es.js +2 -2
- package/dist/reduce.es.min.js +2 -2
- package/dist/reduce.js +2 -2
- package/dist/reduce.min.js +2 -2
- package/dist/reduce.mjs +2 -2
- package/dist/rubico.es.js +34 -52
- package/dist/rubico.es.min.js +3 -3
- package/dist/rubico.global.js +34 -52
- package/dist/rubico.global.min.js +3 -3
- package/dist/rubico.js +34 -52
- package/dist/rubico.min.js +3 -3
- package/dist/rubico.mjs +34 -52
- package/dist/set.es.js +2 -2
- package/dist/set.es.min.js +2 -2
- package/dist/set.js +2 -2
- package/dist/set.min.js +2 -2
- package/dist/set.mjs +2 -2
- package/dist/some.es.js +2 -2
- package/dist/some.es.min.js +2 -2
- package/dist/some.js +2 -2
- package/dist/some.min.js +2 -2
- package/dist/some.mjs +2 -2
- package/dist/switchCase.es.js +2 -2
- package/dist/switchCase.es.min.js +2 -2
- package/dist/switchCase.js +2 -2
- package/dist/switchCase.min.js +2 -2
- package/dist/switchCase.mjs +2 -2
- package/dist/tap.es.js +2 -2
- package/dist/tap.es.min.js +2 -2
- package/dist/tap.js +2 -2
- package/dist/tap.min.js +2 -2
- package/dist/tap.mjs +2 -2
- package/dist/thunkify.es.js +2 -2
- package/dist/thunkify.es.min.js +2 -2
- package/dist/thunkify.js +2 -2
- package/dist/thunkify.min.js +2 -2
- package/dist/thunkify.mjs +2 -2
- package/dist/transform.es.js +2 -2
- package/dist/transform.es.min.js +2 -2
- package/dist/transform.js +2 -2
- package/dist/transform.min.js +2 -2
- package/dist/transform.mjs +2 -2
- package/dist/tryCatch.es.js +2 -2
- package/dist/tryCatch.es.min.js +2 -2
- package/dist/tryCatch.js +2 -2
- package/dist/tryCatch.min.js +2 -2
- package/dist/tryCatch.mjs +2 -2
- package/dist/x/append.es.js +2 -2
- package/dist/x/append.es.min.js +2 -2
- package/dist/x/append.js +2 -2
- package/dist/x/append.min.js +2 -2
- package/dist/x/append.mjs +2 -2
- package/dist/x/callProp.es.js +2 -2
- package/dist/x/callProp.es.min.js +2 -2
- package/dist/x/callProp.js +2 -2
- package/dist/x/callProp.min.js +2 -2
- package/dist/x/callProp.mjs +2 -2
- package/dist/x/defaultsDeep.es.js +2 -2
- package/dist/x/defaultsDeep.es.min.js +2 -2
- package/dist/x/defaultsDeep.js +2 -2
- package/dist/x/defaultsDeep.min.js +2 -2
- package/dist/x/defaultsDeep.mjs +2 -2
- package/dist/x/differenceWith.es.js +2 -2
- package/dist/x/differenceWith.es.min.js +2 -2
- package/dist/x/differenceWith.js +2 -2
- package/dist/x/differenceWith.min.js +2 -2
- package/dist/x/differenceWith.mjs +2 -2
- package/dist/x/filterOut.es.js +5 -3
- package/dist/x/filterOut.es.min.js +3 -3
- package/dist/x/filterOut.js +5 -3
- package/dist/x/filterOut.min.js +3 -3
- package/dist/x/filterOut.mjs +5 -3
- package/dist/x/find.es.js +2 -2
- package/dist/x/find.es.min.js +2 -2
- package/dist/x/find.js +2 -2
- package/dist/x/find.min.js +2 -2
- package/dist/x/find.mjs +2 -2
- package/dist/x/findIndex.es.js +2 -2
- package/dist/x/findIndex.es.min.js +2 -2
- package/dist/x/findIndex.js +2 -2
- package/dist/x/findIndex.min.js +2 -2
- package/dist/x/findIndex.mjs +2 -2
- package/dist/x/first.es.js +2 -2
- package/dist/x/first.es.min.js +2 -2
- package/dist/x/first.js +2 -2
- package/dist/x/first.min.js +2 -2
- package/dist/x/first.mjs +2 -2
- package/dist/x/flatten.es.js +2 -2
- package/dist/x/flatten.es.min.js +2 -2
- package/dist/x/flatten.js +2 -2
- package/dist/x/flatten.min.js +2 -2
- package/dist/x/flatten.mjs +2 -2
- package/dist/x/groupBy.es.js +2 -2
- package/dist/x/groupBy.es.min.js +2 -2
- package/dist/x/groupBy.js +2 -2
- package/dist/x/groupBy.min.js +2 -2
- package/dist/x/groupBy.mjs +2 -2
- package/dist/x/has.es.js +2 -2
- package/dist/x/has.es.min.js +2 -2
- package/dist/x/has.js +2 -2
- package/dist/x/has.min.js +2 -2
- package/dist/x/has.mjs +2 -2
- package/dist/x/identity.es.js +2 -2
- package/dist/x/identity.es.min.js +2 -2
- package/dist/x/identity.js +2 -2
- package/dist/x/identity.min.js +2 -2
- package/dist/x/identity.mjs +2 -2
- package/dist/x/includes.es.js +2 -2
- package/dist/x/includes.es.min.js +2 -2
- package/dist/x/includes.js +2 -2
- package/dist/x/includes.min.js +2 -2
- package/dist/x/includes.mjs +2 -2
- package/dist/x/isDeepEqual.es.js +2 -2
- package/dist/x/isDeepEqual.es.min.js +2 -2
- package/dist/x/isDeepEqual.js +2 -2
- package/dist/x/isDeepEqual.min.js +2 -2
- package/dist/x/isDeepEqual.mjs +2 -2
- package/dist/x/isEmpty.es.js +2 -2
- package/dist/x/isEmpty.es.min.js +2 -2
- package/dist/x/isEmpty.js +2 -2
- package/dist/x/isEmpty.min.js +2 -2
- package/dist/x/isEmpty.mjs +2 -2
- package/dist/x/isEqual.es.js +2 -2
- package/dist/x/isEqual.es.min.js +2 -2
- package/dist/x/isEqual.js +2 -2
- package/dist/x/isEqual.min.js +2 -2
- package/dist/x/isEqual.mjs +2 -2
- package/dist/x/isFunction.es.js +2 -2
- package/dist/x/isFunction.es.min.js +2 -2
- package/dist/x/isFunction.js +2 -2
- package/dist/x/isFunction.min.js +2 -2
- package/dist/x/isFunction.mjs +2 -2
- package/dist/x/isIn.es.js +2 -2
- package/dist/x/isIn.es.min.js +2 -2
- package/dist/x/isIn.js +2 -2
- package/dist/x/isIn.min.js +2 -2
- package/dist/x/isIn.mjs +2 -2
- package/dist/x/isObject.es.js +2 -2
- package/dist/x/isObject.es.min.js +2 -2
- package/dist/x/isObject.js +2 -2
- package/dist/x/isObject.min.js +2 -2
- package/dist/x/isObject.mjs +2 -2
- package/dist/x/isString.es.js +2 -2
- package/dist/x/isString.es.min.js +2 -2
- package/dist/x/isString.js +2 -2
- package/dist/x/isString.min.js +2 -2
- package/dist/x/isString.mjs +2 -2
- package/dist/x/keys.es.js +2 -2
- package/dist/x/keys.es.min.js +2 -2
- package/dist/x/keys.js +2 -2
- package/dist/x/keys.min.js +2 -2
- package/dist/x/keys.mjs +2 -2
- package/dist/x/last.es.js +2 -2
- package/dist/x/last.es.min.js +2 -2
- package/dist/x/last.js +2 -2
- package/dist/x/last.min.js +2 -2
- package/dist/x/last.mjs +2 -2
- package/dist/x/maxBy.es.js +2 -2
- package/dist/x/maxBy.es.min.js +2 -2
- package/dist/x/maxBy.js +2 -2
- package/dist/x/maxBy.min.js +2 -2
- package/dist/x/maxBy.mjs +2 -2
- package/dist/x/noop.es.js +2 -2
- package/dist/x/noop.es.min.js +2 -2
- package/dist/x/noop.js +2 -2
- package/dist/x/noop.min.js +2 -2
- package/dist/x/noop.mjs +2 -2
- package/dist/x/pluck.es.js +31 -31
- package/dist/x/pluck.es.min.js +3 -3
- package/dist/x/pluck.js +31 -31
- package/dist/x/pluck.min.js +3 -3
- package/dist/x/pluck.mjs +31 -31
- package/dist/x/prepend.es.js +2 -2
- package/dist/x/prepend.es.min.js +2 -2
- package/dist/x/prepend.js +2 -2
- package/dist/x/prepend.min.js +2 -2
- package/dist/x/prepend.mjs +2 -2
- package/dist/x/size.es.js +2 -2
- package/dist/x/size.es.min.js +2 -2
- package/dist/x/size.js +2 -2
- package/dist/x/size.min.js +2 -2
- package/dist/x/size.mjs +2 -2
- package/dist/x/trace.es.js +2 -2
- package/dist/x/trace.es.min.js +2 -2
- package/dist/x/trace.js +2 -2
- package/dist/x/trace.min.js +2 -2
- package/dist/x/trace.mjs +2 -2
- package/dist/x/unionWith.es.js +2 -2
- package/dist/x/unionWith.es.min.js +2 -2
- package/dist/x/unionWith.js +2 -2
- package/dist/x/unionWith.min.js +2 -2
- package/dist/x/unionWith.mjs +2 -2
- package/dist/x/uniq.es.js +2 -2
- package/dist/x/uniq.es.min.js +2 -2
- package/dist/x/uniq.js +2 -2
- package/dist/x/uniq.min.js +2 -2
- package/dist/x/uniq.mjs +2 -2
- package/dist/x/unless.es.js +2 -2
- package/dist/x/unless.es.min.js +2 -2
- package/dist/x/unless.js +2 -2
- package/dist/x/unless.min.js +2 -2
- package/dist/x/unless.mjs +2 -2
- package/dist/x/values.es.js +2 -2
- package/dist/x/values.es.min.js +2 -2
- package/dist/x/values.js +2 -2
- package/dist/x/values.min.js +2 -2
- package/dist/x/values.mjs +2 -2
- package/dist/x/when.es.js +2 -2
- package/dist/x/when.es.min.js +2 -2
- package/dist/x/when.js +2 -2
- package/dist/x/when.min.js +2 -2
- package/dist/x/when.mjs +2 -2
- package/es.js +34 -52
- package/filter.js +41 -45
- package/flatMap.js +24 -27
- package/index.js +34 -52
- package/map.js +67 -89
- package/package.json +1 -3
- package/reduce.js +44 -82
- package/transform.js +24 -32
package/map.js
CHANGED
|
@@ -93,93 +93,82 @@ const _map = function (value, f) {
|
|
|
93
93
|
*
|
|
94
94
|
* @synopsis
|
|
95
95
|
* ```coffeescript [specscript]
|
|
96
|
-
* type
|
|
96
|
+
* type Functor = Array|Object|Set|Generator|AsyncGenerator
|
|
97
97
|
*
|
|
98
98
|
* type Mapper = (
|
|
99
|
-
*
|
|
99
|
+
* item any,
|
|
100
100
|
* indexOrKey number|string|any,
|
|
101
|
-
*
|
|
101
|
+
* f Map|Functor
|
|
102
102
|
* )=>(resultItem Promise|any)
|
|
103
103
|
*
|
|
104
|
-
* map(
|
|
105
|
-
* map(
|
|
104
|
+
* map(f Promise|Map|Functor, mapper Mapper) -> result Promise|Map|Functor
|
|
105
|
+
* map(mapper Mapper)(f Map|Functor) -> result Promise|Map|Functor
|
|
106
106
|
* ```
|
|
107
107
|
*
|
|
108
108
|
* @description
|
|
109
|
-
* Applies a
|
|
109
|
+
* Applies a mapper function to each item of a functor, returning a functor of the same type with the transformed items. The order of the items is maintained.
|
|
110
|
+
*
|
|
111
|
+
* The following data types are considered functors:
|
|
112
|
+
* * `array`
|
|
113
|
+
* * `object`
|
|
114
|
+
* * `set`
|
|
115
|
+
* * `iterator`
|
|
116
|
+
* * `async iterator`
|
|
110
117
|
*
|
|
111
|
-
*
|
|
112
|
-
* * `Object`
|
|
113
|
-
* * `Set`
|
|
114
|
-
* * `Map`
|
|
115
|
-
* * `Iterator`/`Generator`
|
|
116
|
-
* * `AsyncIterator`/`AsyncGenerator`
|
|
118
|
+
* The mapper function defines the transformation of a given item in the provided functor.
|
|
117
119
|
*
|
|
118
|
-
*
|
|
120
|
+
* ```javascript
|
|
121
|
+
* const mapper = function (item) {
|
|
122
|
+
* // resultItem is the result of some operation on item
|
|
123
|
+
* return resultItem
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* `map` works for arrays.
|
|
119
128
|
*
|
|
120
129
|
* ```javascript [playground]
|
|
121
130
|
* const square = number => number ** 2
|
|
122
131
|
*
|
|
123
132
|
* const array = [1, 2, 3, 4, 5]
|
|
124
133
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* ) // [1, 4, 9, 16, 25]
|
|
128
|
-
*
|
|
129
|
-
* console.log(
|
|
130
|
-
* map(square)(array)
|
|
131
|
-
* ) // [1, 4, 9, 16, 25]
|
|
134
|
+
* const result = map(array, square)
|
|
135
|
+
* console.log(result) // [1, 4, 9, 16, 25]
|
|
132
136
|
* ```
|
|
133
137
|
*
|
|
134
|
-
*
|
|
138
|
+
* The mapper function may be asynchronous, in which case it is applied concurrently.
|
|
135
139
|
*
|
|
136
140
|
* ```javascript [playground]
|
|
137
|
-
* const
|
|
141
|
+
* const asyncSquare = async number => number ** 2
|
|
138
142
|
*
|
|
139
|
-
* const
|
|
140
|
-
*
|
|
141
|
-
* console.log(
|
|
142
|
-
* map(square)(obj)
|
|
143
|
-
* ) // { a: 1, b: 4, c: 9, d: 16, e: 25 }
|
|
143
|
+
* const array = [1, 2, 3, 4, 5]
|
|
144
144
|
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* ) // { a: 1, b: 4, c: 9, d: 16, e: 25 }
|
|
145
|
+
* const promise = map(array, asyncSquare)
|
|
146
|
+
* promise.then(console.log) // [1, 4, 9, 16, 25]
|
|
148
147
|
* ```
|
|
149
148
|
*
|
|
150
|
-
*
|
|
149
|
+
* For objects, `map` applies the mapper function to just the values.
|
|
151
150
|
*
|
|
152
151
|
* ```javascript [playground]
|
|
153
152
|
* const square = number => number ** 2
|
|
154
153
|
*
|
|
155
|
-
* const
|
|
156
|
-
*
|
|
157
|
-
* console.log(
|
|
158
|
-
* map(set, square)
|
|
159
|
-
* ) // [1, 4, 9, 16, 25]
|
|
154
|
+
* const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
|
160
155
|
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* ) // [1, 4, 9, 16, 25]
|
|
156
|
+
* const result = map(obj, square)
|
|
157
|
+
* console.log(result) // { a: 1, b: 4, c: 9, d: 16, e: 25 }
|
|
164
158
|
* ```
|
|
165
159
|
*
|
|
166
|
-
*
|
|
160
|
+
* For maps, `map` applies the mapper function to the values of the entries.
|
|
167
161
|
*
|
|
168
162
|
* ```javascript [playground]
|
|
169
163
|
* const square = number => number ** 2
|
|
170
164
|
*
|
|
171
165
|
* const m = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
|
|
172
166
|
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* ) // Map { 'a' => 1, 'b' => 4, 'c' => 9, 'd' => 16, 'e' => 25 }
|
|
176
|
-
*
|
|
177
|
-
* console.log(
|
|
178
|
-
* map(m, square)
|
|
179
|
-
* ) // Map { 'a' => 1, 'b' => 4, 'c' => 9, 'd' => 16, 'e' => 25 }
|
|
167
|
+
* const result = map(m, square)
|
|
168
|
+
* console.log(result) // Map { 'a' => 1, 'b' => 4, 'c' => 9, 'd' => 16, 'e' => 25 }
|
|
180
169
|
* ```
|
|
181
170
|
*
|
|
182
|
-
*
|
|
171
|
+
* For generators, `map` applies the mapper function lazily to each value of the iterator, creating a new iterator with transformed items.
|
|
183
172
|
*
|
|
184
173
|
* ```javascript [playground]
|
|
185
174
|
* const capitalize = string => string.toUpperCase()
|
|
@@ -190,16 +179,13 @@ const _map = function (value, f) {
|
|
|
190
179
|
*
|
|
191
180
|
* const abcGenerator = abcGeneratorFunc()
|
|
192
181
|
* const ABCGenerator = map(abcGeneratorFunc(), capitalize)
|
|
193
|
-
* const ABCGenerator2 = map(capitalize)(abcGeneratorFunc())
|
|
194
182
|
*
|
|
195
183
|
* console.log([...abcGenerator]) // ['a', 'b', 'c']
|
|
196
184
|
*
|
|
197
185
|
* console.log([...ABCGenerator]) // ['A', 'B', 'C']
|
|
198
|
-
*
|
|
199
|
-
* console.log([...ABCGenerator2]) // ['A', 'B', 'C']
|
|
200
186
|
* ```
|
|
201
187
|
*
|
|
202
|
-
*
|
|
188
|
+
* For async generators, `map` applies the mapper function lazily to each value of the async generator, creating a new async generator with transformed items.
|
|
203
189
|
*
|
|
204
190
|
* ```javascript [playground]
|
|
205
191
|
* const capitalize = string => string.toUpperCase()
|
|
@@ -210,7 +196,6 @@ const _map = function (value, f) {
|
|
|
210
196
|
*
|
|
211
197
|
* const abcAsyncGenerator = abcAsyncGeneratorFunc()
|
|
212
198
|
* const ABCGenerator = map(abcAsyncGeneratorFunc(), capitalize)
|
|
213
|
-
* const ABCGenerator2 = map(capitalize)(abcAsyncGeneratorFunc())
|
|
214
199
|
*
|
|
215
200
|
* ;(async function () {
|
|
216
201
|
* for await (const letter of abcAsyncGenerator) {
|
|
@@ -226,13 +211,6 @@ const _map = function (value, f) {
|
|
|
226
211
|
* // B
|
|
227
212
|
* // C
|
|
228
213
|
* }
|
|
229
|
-
*
|
|
230
|
-
* for await (const letter of ABCGenerator2) {
|
|
231
|
-
* console.log(letter)
|
|
232
|
-
* // A
|
|
233
|
-
* // B
|
|
234
|
-
* // C
|
|
235
|
-
* }
|
|
236
214
|
* })()
|
|
237
215
|
* ```
|
|
238
216
|
*
|
|
@@ -334,15 +312,15 @@ map.entries = function mapEntries(arg0, arg1) {
|
|
|
334
312
|
*
|
|
335
313
|
* @synopsis
|
|
336
314
|
* ```coffeescript [specscript]
|
|
337
|
-
* type
|
|
315
|
+
* type Functor = Array|Object|Set|Map
|
|
338
316
|
*
|
|
339
317
|
* type Mapper = (
|
|
340
318
|
* value any,
|
|
341
319
|
* indexOrKey number|string|any,
|
|
342
|
-
*
|
|
320
|
+
* f Functor
|
|
343
321
|
* )=>(mappedItem Promise|any)
|
|
344
322
|
*
|
|
345
|
-
* _mapSeries(
|
|
323
|
+
* _mapSeries(f Functor, f Mapper) -> result Promise|Functor
|
|
346
324
|
* ```
|
|
347
325
|
*/
|
|
348
326
|
const _mapSeries = function (collection, f) {
|
|
@@ -373,16 +351,16 @@ const _mapSeries = function (collection, f) {
|
|
|
373
351
|
*
|
|
374
352
|
* @synopsis
|
|
375
353
|
* ```coffeescript [specscript]
|
|
376
|
-
* type
|
|
354
|
+
* type Functor = Array|Object|Set|Map
|
|
377
355
|
*
|
|
378
356
|
* type Mapper = (
|
|
379
357
|
* value any,
|
|
380
358
|
* indexOrKey number|string|any,
|
|
381
|
-
*
|
|
359
|
+
* f Functor
|
|
382
360
|
* )=>(mappedItem Promise|any)
|
|
383
361
|
*
|
|
384
|
-
* map.series(
|
|
385
|
-
* map.series(f Mapper)(
|
|
362
|
+
* map.series(f Promise|Functor, f Mapper) -> result Functor
|
|
363
|
+
* map.series(f Mapper)(f Functor) -> result Functor
|
|
386
364
|
* ```
|
|
387
365
|
*
|
|
388
366
|
* @description
|
|
@@ -425,31 +403,31 @@ map.series = function mapSeries(arg0, arg1) {
|
|
|
425
403
|
*
|
|
426
404
|
* @synopsis
|
|
427
405
|
* ```coffeescript [specscript]
|
|
428
|
-
* type
|
|
406
|
+
* type Functor = Array|Object|Set|Map
|
|
429
407
|
*
|
|
430
|
-
* _mapPool(
|
|
408
|
+
* _mapPool(f Functor, concurrency number, mapper function) -> result Promise|Functor
|
|
431
409
|
* ```
|
|
432
410
|
*/
|
|
433
|
-
const _mapPool = function (
|
|
434
|
-
if (isArray(
|
|
435
|
-
return arrayMapPool(
|
|
411
|
+
const _mapPool = function (f, concurrency, mapper) {
|
|
412
|
+
if (isArray(f)) {
|
|
413
|
+
return arrayMapPool(f, concurrency, mapper)
|
|
436
414
|
}
|
|
437
|
-
if (
|
|
438
|
-
throw new TypeError(`invalid
|
|
415
|
+
if (f == null) {
|
|
416
|
+
throw new TypeError(`invalid functor ${f}`)
|
|
439
417
|
}
|
|
440
|
-
if (typeof
|
|
441
|
-
return stringMapPool(
|
|
418
|
+
if (typeof f == 'string' || f.constructor == String) {
|
|
419
|
+
return stringMapPool(f, concurrency, mapper)
|
|
442
420
|
}
|
|
443
|
-
if (
|
|
444
|
-
return setMapPool(
|
|
421
|
+
if (f.constructor == Set) {
|
|
422
|
+
return setMapPool(f, concurrency, mapper)
|
|
445
423
|
}
|
|
446
|
-
if (
|
|
447
|
-
return mapMapPool(
|
|
424
|
+
if (f.constructor == Map) {
|
|
425
|
+
return mapMapPool(f, concurrency, mapper)
|
|
448
426
|
}
|
|
449
|
-
if (
|
|
450
|
-
return objectMapPool(
|
|
427
|
+
if (f.constructor == Object) {
|
|
428
|
+
return objectMapPool(f, concurrency, mapper)
|
|
451
429
|
}
|
|
452
|
-
throw new TypeError(`invalid
|
|
430
|
+
throw new TypeError(`invalid functor ${f}`)
|
|
453
431
|
}
|
|
454
432
|
|
|
455
433
|
/**
|
|
@@ -457,15 +435,15 @@ const _mapPool = function (collection, concurrency, f) {
|
|
|
457
435
|
*
|
|
458
436
|
* @synopsis
|
|
459
437
|
* ```coffeescript [specscript]
|
|
460
|
-
* type
|
|
438
|
+
* type Functor = Array|Object|Set|Map
|
|
461
439
|
*
|
|
462
440
|
* map.pool(
|
|
463
441
|
* concurrency number,
|
|
464
442
|
* mapper (value any)=>Promise|any,
|
|
465
|
-
* )(
|
|
443
|
+
* )(f Functor) -> result Promise|Array
|
|
466
444
|
*
|
|
467
445
|
* map.pool(
|
|
468
|
-
*
|
|
446
|
+
* f Functor,
|
|
469
447
|
* concurrency number,
|
|
470
448
|
* mapper (value any)=>Promise|any,
|
|
471
449
|
* ) -> result Promise|Array
|
|
@@ -517,15 +495,15 @@ map.pool = function mapPool(arg0, arg1, arg2) {
|
|
|
517
495
|
*
|
|
518
496
|
* @synopsis
|
|
519
497
|
* ```coffeescript [specscript]
|
|
520
|
-
* type
|
|
498
|
+
* type Functor = Array|Object|Set|Map
|
|
521
499
|
*
|
|
522
500
|
* map.rate(
|
|
523
501
|
* rate number,
|
|
524
502
|
* f (value any)=>Promise|any,
|
|
525
|
-
* )(
|
|
503
|
+
* )(f Functor) -> result Promise|Array
|
|
526
504
|
*
|
|
527
505
|
* map.rate(
|
|
528
|
-
*
|
|
506
|
+
* f Functor,
|
|
529
507
|
* rate number,
|
|
530
508
|
* f (value any)=>Promise|any,
|
|
531
509
|
* ) -> result Promise|Array
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rubico",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.6",
|
|
4
4
|
"description": "[a]synchronous functional programming",
|
|
5
5
|
"author": "Richard Tong",
|
|
6
6
|
"license": "MIT",
|
|
@@ -115,7 +115,6 @@
|
|
|
115
115
|
"async": "latest",
|
|
116
116
|
"bluebird": "latest",
|
|
117
117
|
"codecov": "^3.7.1",
|
|
118
|
-
"eslint": "^9.22.0",
|
|
119
118
|
"fantasy-land": "latest",
|
|
120
119
|
"lodash": "latest",
|
|
121
120
|
"mocha": "^11.1.0",
|
|
@@ -129,7 +128,6 @@
|
|
|
129
128
|
"scripts": {
|
|
130
129
|
"test": "mocha test.js *.test.js */**.test.js",
|
|
131
130
|
"test-coverage": "nyc mocha test.js x/*.test.js monad/*.test.js",
|
|
132
|
-
"lint": "eslint .",
|
|
133
131
|
"build": "npm run dts && ./build",
|
|
134
132
|
"bench": "./bench",
|
|
135
133
|
"dts": "del *.d.ts _internal/*.d.ts x/*.d.ts && tsc"
|
package/reduce.js
CHANGED
|
@@ -21,19 +21,19 @@ const _reduce = function (collection, reducer, initialValue) {
|
|
|
21
21
|
*
|
|
22
22
|
* @synopsis
|
|
23
23
|
* ```coffeescript [specscript]
|
|
24
|
-
* type Foldable =
|
|
24
|
+
* type Foldable = Iterable|AsyncIterable|Object<value any>
|
|
25
25
|
*
|
|
26
26
|
* type Reducer = (
|
|
27
27
|
* accumulator any,
|
|
28
|
-
*
|
|
28
|
+
* item any,
|
|
29
29
|
* indexOrKey? number|string,
|
|
30
|
-
*
|
|
30
|
+
* f? Map|Foldable,
|
|
31
31
|
* )=>(nextAccumulator Promise|any)
|
|
32
32
|
*
|
|
33
|
-
* type Resolver = (
|
|
33
|
+
* type Resolver = (f Map|Foldable)=>Promise|any
|
|
34
34
|
*
|
|
35
35
|
* reduce(
|
|
36
|
-
*
|
|
36
|
+
* f Map|Foldable,
|
|
37
37
|
* reducer Reducer,
|
|
38
38
|
* initialValue? Resolver|any
|
|
39
39
|
* ) -> result Promise|any
|
|
@@ -41,43 +41,53 @@ const _reduce = function (collection, reducer, initialValue) {
|
|
|
41
41
|
* reduce(
|
|
42
42
|
* reducer Reducer,
|
|
43
43
|
* initialValue? Resolver|any
|
|
44
|
-
* )(
|
|
44
|
+
* )(f Map|Foldable) -> result Promise|any
|
|
45
45
|
* ```
|
|
46
46
|
*
|
|
47
47
|
* @description
|
|
48
|
-
*
|
|
48
|
+
* Reduces a map or foldable to a single value.
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
* * `
|
|
52
|
-
* * `
|
|
53
|
-
* * `
|
|
54
|
-
* * `Iterator`/`Generator`
|
|
55
|
-
* * `AsyncIterator`/`AsyncGenerator`
|
|
50
|
+
* The following data types are considered foldables:
|
|
51
|
+
* * `iterable`
|
|
52
|
+
* * `async iterable`
|
|
53
|
+
* * `object`; only the values of the object are transformed
|
|
56
54
|
*
|
|
57
|
-
*
|
|
55
|
+
* The following data types are considered iterable:
|
|
56
|
+
* * `array`
|
|
57
|
+
* * `set`
|
|
58
|
+
* * `map`
|
|
59
|
+
*
|
|
60
|
+
* The reducing operation is dictated by a provided reducer function, which defines a transformation between the accumulator and a given item of the map or foldable.
|
|
61
|
+
*
|
|
62
|
+
* ```javascript
|
|
63
|
+
* const reducer = function (accumulator, item) {
|
|
64
|
+
* const nextAccumulator = f(accumulator, item)
|
|
65
|
+
* return nextAccumulator
|
|
66
|
+
* // nextAccumulator becomes the accumulator for the next iteration and invocation of the reducer
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* The result of the last invocation of the reducer is the result of the reducing operation. The reducer may be asynchronous and return a promise, in which case the promise is resolved for its value before continuing with the reducing operation.
|
|
71
|
+
*
|
|
72
|
+
* `reduce` executes a reducer function for each item of the array in order. If no initial value is provided, `reduce` uses the first item of the map or foldable as the initial value and starts iterating from the second item of the map or foldable.
|
|
58
73
|
*
|
|
59
74
|
* ```javascript [playground]
|
|
60
75
|
* const max = (a, b) => a > b ? a : b
|
|
61
76
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* ) // 5
|
|
65
|
-
*
|
|
66
|
-
* console.log(
|
|
67
|
-
* reduce(max)([1, 3, 5, 4, 2])
|
|
68
|
-
* ) // 5
|
|
77
|
+
* const result = reduce([1, 3, 5, 4, 2], max)
|
|
78
|
+
* console.log(result) // 5
|
|
69
79
|
* ```
|
|
70
80
|
*
|
|
71
|
-
* If an
|
|
81
|
+
* If an initial value is provided, the accumulator starts as the initial value rather than the first item of the map or foldable.
|
|
72
82
|
*
|
|
73
83
|
* ```javascript [playground]
|
|
74
84
|
* const add = (a, b) => a + b
|
|
75
85
|
*
|
|
76
|
-
*
|
|
77
|
-
* console.log(
|
|
86
|
+
* const result = reduce([1, 2, 3, 4, 5], add, 0)
|
|
87
|
+
* console.log(result) // 15
|
|
78
88
|
* ```
|
|
79
89
|
*
|
|
80
|
-
* If the initialization parameter is a function, it is treated as a resolver and called with the
|
|
90
|
+
* If the initialization parameter is a function, it is treated as a resolver of the initial value and called with the map or foldable.
|
|
81
91
|
*
|
|
82
92
|
* ```javascript [playground]
|
|
83
93
|
* const concatSquares = (array, value) => array.concat(value ** 2)
|
|
@@ -86,90 +96,42 @@ const _reduce = function (collection, reducer, initialValue) {
|
|
|
86
96
|
*
|
|
87
97
|
* const array = [1, 2, 3, 4, 5]
|
|
88
98
|
*
|
|
89
|
-
* console.log(reduce(concatSquares, contrivedInitializer)(array))
|
|
90
|
-
* // ['initial length 5', 1, 4, 9, 16, 25]
|
|
91
99
|
* console.log(reduce(array, concatSquares, contrivedInitializer))
|
|
92
100
|
* // ['initial length 5', 1, 4, 9, 16, 25]
|
|
93
101
|
* ```
|
|
94
102
|
*
|
|
95
|
-
* For objects
|
|
103
|
+
* For objects, `reduce` iterates over just the values.
|
|
96
104
|
*
|
|
97
105
|
* ```javascript [playground]
|
|
98
106
|
* const add = (a, b) => a + b
|
|
99
107
|
*
|
|
100
108
|
* const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
|
101
109
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* ) // 15
|
|
105
|
-
*
|
|
106
|
-
* console.log(
|
|
107
|
-
* reduce(add)(obj)
|
|
108
|
-
* ) // 15
|
|
110
|
+
* const result = reduce(obj, add)
|
|
111
|
+
* console.log(result) // 15
|
|
109
112
|
* ```
|
|
110
113
|
*
|
|
111
|
-
* For
|
|
112
|
-
*
|
|
113
|
-
* ```javascript [playground]
|
|
114
|
-
* const add = (a, b) => a + b
|
|
115
|
-
*
|
|
116
|
-
* const set = new Set([1, 2, 3, 4, 5])
|
|
117
|
-
*
|
|
118
|
-
* console.log(
|
|
119
|
-
* reduce(set, add)
|
|
120
|
-
* ) // 15
|
|
121
|
-
*
|
|
122
|
-
* console.log(
|
|
123
|
-
* reduce(add)(set)
|
|
124
|
-
* ) // 15
|
|
125
|
-
* ```
|
|
126
|
-
*
|
|
127
|
-
* For maps (type `Map`), `reduce` executes the reducer function for each value of each entry of the map. On each iteration, the reducer is passed the accumulator, the map item, the key of the map item, and a reference to the original map.
|
|
114
|
+
* For maps, `reduce` iterates over the values of the entries.
|
|
128
115
|
*
|
|
129
116
|
* ```javascript [playground]
|
|
130
117
|
* const add = (a, b) => a + b
|
|
131
118
|
*
|
|
132
119
|
* const m = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
|
|
133
120
|
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* ) // 15
|
|
137
|
-
*
|
|
138
|
-
* console.log(
|
|
139
|
-
* reduce(add)(m)
|
|
140
|
-
* ) // 15
|
|
141
|
-
* ```
|
|
142
|
-
*
|
|
143
|
-
* For iterators (type `Iterator`) and generators (type `Generator`), `reduce` executes the reducer function for each value of the iterator/generator. On each iteration, the reducer is passed the accumulator and the item of the iteration. The iterator/generator is consumed in the process.
|
|
144
|
-
*
|
|
145
|
-
* ```javascript [playground]
|
|
146
|
-
* const add = (a, b) => a + b
|
|
147
|
-
*
|
|
148
|
-
* const generate12345 = function* () {
|
|
149
|
-
* yield 1; yield 2; yield 3; yield 4; yield 5
|
|
150
|
-
* }
|
|
151
|
-
*
|
|
152
|
-
* console.log(
|
|
153
|
-
* reduce(generate12345(), add)
|
|
154
|
-
* ) // 15
|
|
155
|
-
*
|
|
156
|
-
* console.log(
|
|
157
|
-
* reduce(add)(generate12345())
|
|
158
|
-
* ) // 15
|
|
121
|
+
* const result = reduce(m, add)
|
|
122
|
+
* console.log(result) // 15
|
|
159
123
|
* ```
|
|
160
124
|
*
|
|
161
|
-
*
|
|
125
|
+
* `reduce` works for async iterators.
|
|
162
126
|
*
|
|
163
127
|
* ```javascript [playground]
|
|
164
128
|
* const asyncAdd = async (a, b) => a + b
|
|
165
129
|
*
|
|
166
|
-
* const
|
|
130
|
+
* const asyncGenerate = async function* () {
|
|
167
131
|
* yield 1; yield 2; yield 3; yield 4; yield 5
|
|
168
132
|
* }
|
|
169
133
|
*
|
|
170
|
-
* reduce(
|
|
171
|
-
*
|
|
172
|
-
* reduce(asyncAdd)(asyncGenerate12345()).then(console.log) // 15
|
|
134
|
+
* reduce(asyncGenerate(), asyncAdd).then(console.log) // 15
|
|
173
135
|
* ```
|
|
174
136
|
*
|
|
175
137
|
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
package/transform.js
CHANGED
|
@@ -26,39 +26,45 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
26
26
|
* type Reducer = (
|
|
27
27
|
* accumulator any,
|
|
28
28
|
* value any,
|
|
29
|
-
* indexOrKey
|
|
30
|
-
*
|
|
29
|
+
* indexOrKey number|string,
|
|
30
|
+
* f Foldable,
|
|
31
31
|
* )=>(nextAccumulator Promise|any)
|
|
32
32
|
*
|
|
33
33
|
* type Transducer = Reducer=>Reducer
|
|
34
34
|
*
|
|
35
|
-
* type
|
|
35
|
+
* type Semigroup =
|
|
36
36
|
* Array|String|Set|TypedArray|{ concat: function }|{ write: function }|Object
|
|
37
37
|
*
|
|
38
|
-
* type
|
|
38
|
+
* type SemigroupResolver = (f Foldable)=>Promise|Semigroup
|
|
39
39
|
*
|
|
40
40
|
* transform(
|
|
41
|
-
*
|
|
41
|
+
* f Foldable,
|
|
42
42
|
* transducer Transducer,
|
|
43
|
-
* initialValue?
|
|
44
|
-
* ) -> result Promise|
|
|
43
|
+
* initialValue? Semigroup|SemigroupResolver,
|
|
44
|
+
* ) -> result Promise|Semigroup
|
|
45
45
|
*
|
|
46
46
|
* transform(
|
|
47
47
|
* transducer Transducer,
|
|
48
|
-
* initialValue?
|
|
49
|
-
* )(
|
|
48
|
+
* initialValue? Semigroup|SemigroupResolver,
|
|
49
|
+
* )(f Foldable) -> result Promise|Semigroup
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
52
|
* @description
|
|
53
|
-
* Transforms a
|
|
53
|
+
* Transforms a foldable into a semigroup. The type of transformation depends on the type of semigroup provided as the initial value. If the initial value is a function it is treated as a resolver of the semigroup.
|
|
54
54
|
*
|
|
55
|
-
*
|
|
55
|
+
* The following data types are considered foldables:
|
|
56
|
+
* * `iterable`
|
|
57
|
+
* * `async iterable`
|
|
58
|
+
* * `object`; only the values of the object are transformed
|
|
59
|
+
*
|
|
60
|
+
* The following data types are considered semigroups:
|
|
61
|
+
* * `array`; concatenation defined by `result.concat(values)`
|
|
56
62
|
* * `string`; concatenation defined by `result + values`
|
|
57
|
-
* * `
|
|
58
|
-
* * `
|
|
63
|
+
* * `set`; concatenation defined by `result.add(...values)`
|
|
64
|
+
* * `binary`; concatenation defined by `result.set(prevResult); result.set(values, offset)`
|
|
59
65
|
* * `{ concat: function }`; concatenation defined by `result.concat(values)`
|
|
60
66
|
* * `{ write: function }`; concatenation defined by `result.write(item)`
|
|
61
|
-
* * `
|
|
67
|
+
* * `object`; concatenation defined by `({ ...result, ...values })`
|
|
62
68
|
*
|
|
63
69
|
* `transform` can transform any of the above collections into any of the other above collections.
|
|
64
70
|
*
|
|
@@ -93,7 +99,7 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
93
99
|
* ) // Uint8Array(3) [ 1, 9, 25 ]
|
|
94
100
|
* ```
|
|
95
101
|
*
|
|
96
|
-
* `transform` arrays into objects that implement `.concat`.
|
|
102
|
+
* `transform` transforms arrays into objects that implement `.concat`.
|
|
97
103
|
*
|
|
98
104
|
* ```javascript [playground]
|
|
99
105
|
* const square = number => number ** 2
|
|
@@ -113,9 +119,9 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
113
119
|
* // 25
|
|
114
120
|
* ```
|
|
115
121
|
*
|
|
116
|
-
* `transform` an async generator into `process.stdout`, a Node.js writable stream that implements `.write`.
|
|
122
|
+
* `transform` transforms an async generator into `process.stdout`, a Node.js writable stream that implements `.write`.
|
|
117
123
|
*
|
|
118
|
-
* ```javascript
|
|
124
|
+
* ```javascript
|
|
119
125
|
* const { pipe, compose, transform } = rubico
|
|
120
126
|
* // global Transducer
|
|
121
127
|
*
|
|
@@ -133,28 +139,14 @@ const _transform = function (collection, transducer, initialValue) {
|
|
|
133
139
|
* }
|
|
134
140
|
* }
|
|
135
141
|
*
|
|
136
|
-
* const Stdout = {
|
|
137
|
-
* concat(...args) {
|
|
138
|
-
* console.log(...args)
|
|
139
|
-
* return this
|
|
140
|
-
* },
|
|
141
|
-
* }
|
|
142
|
-
*
|
|
143
142
|
* transform(
|
|
144
143
|
* streamRandomInts(10),
|
|
145
144
|
* compose([
|
|
146
145
|
* Transducer.map(square),
|
|
147
146
|
* Transducer.map(toString),
|
|
148
147
|
* ]),
|
|
149
|
-
*
|
|
148
|
+
* process.stdout // 2893600784289441449001600409684644624324923044411225
|
|
150
149
|
* )
|
|
151
|
-
* // 8281
|
|
152
|
-
* // 8836
|
|
153
|
-
* // 1156
|
|
154
|
-
* // 8649
|
|
155
|
-
* // 5625
|
|
156
|
-
* // 2500
|
|
157
|
-
* // ...
|
|
158
150
|
* ```
|
|
159
151
|
*
|
|
160
152
|
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|