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.
Files changed (361) hide show
  1. package/README.md +16 -20
  2. package/Transducer.js +37 -58
  3. package/__.js +3 -3
  4. package/always.js +4 -4
  5. package/and.js +34 -26
  6. package/assign.js +2 -2
  7. package/compose.js +1 -0
  8. package/curry.js +48 -28
  9. package/dist/Transducer.es.js +1 -1
  10. package/dist/Transducer.es.min.js +1 -1
  11. package/dist/Transducer.js +1 -1
  12. package/dist/Transducer.min.js +1 -1
  13. package/dist/Transducer.mjs +1 -1
  14. package/dist/__.es.js +1 -1
  15. package/dist/__.es.min.js +1 -1
  16. package/dist/__.js +1 -1
  17. package/dist/__.min.js +1 -1
  18. package/dist/__.mjs +1 -1
  19. package/dist/all.es.js +1 -1
  20. package/dist/all.es.min.js +1 -1
  21. package/dist/all.js +1 -1
  22. package/dist/all.min.js +1 -1
  23. package/dist/all.mjs +1 -1
  24. package/dist/always.es.js +1 -1
  25. package/dist/always.es.min.js +1 -1
  26. package/dist/always.js +1 -1
  27. package/dist/always.min.js +1 -1
  28. package/dist/always.mjs +1 -1
  29. package/dist/and.es.js +1 -1
  30. package/dist/and.es.min.js +1 -1
  31. package/dist/and.js +1 -1
  32. package/dist/and.min.js +1 -1
  33. package/dist/and.mjs +1 -1
  34. package/dist/assign.es.js +1 -1
  35. package/dist/assign.es.min.js +1 -1
  36. package/dist/assign.js +1 -1
  37. package/dist/assign.min.js +1 -1
  38. package/dist/assign.mjs +1 -1
  39. package/dist/compose.es.js +1 -1
  40. package/dist/compose.es.min.js +1 -1
  41. package/dist/compose.js +1 -1
  42. package/dist/compose.min.js +1 -1
  43. package/dist/compose.mjs +1 -1
  44. package/dist/curry.es.js +1 -1
  45. package/dist/curry.es.min.js +1 -1
  46. package/dist/curry.js +1 -1
  47. package/dist/curry.min.js +1 -1
  48. package/dist/curry.mjs +1 -1
  49. package/dist/eq.es.js +1 -1
  50. package/dist/eq.es.min.js +1 -1
  51. package/dist/eq.js +1 -1
  52. package/dist/eq.min.js +1 -1
  53. package/dist/eq.mjs +1 -1
  54. package/dist/every.es.js +1 -1
  55. package/dist/every.es.min.js +1 -1
  56. package/dist/every.js +1 -1
  57. package/dist/every.min.js +1 -1
  58. package/dist/every.mjs +1 -1
  59. package/dist/filter.es.js +113 -19
  60. package/dist/filter.es.min.js +2 -2
  61. package/dist/filter.js +113 -19
  62. package/dist/filter.min.js +2 -2
  63. package/dist/filter.mjs +113 -19
  64. package/dist/flatMap.es.js +1 -1
  65. package/dist/flatMap.es.min.js +1 -1
  66. package/dist/flatMap.js +1 -1
  67. package/dist/flatMap.min.js +1 -1
  68. package/dist/flatMap.mjs +1 -1
  69. package/dist/forEach.es.js +1 -1
  70. package/dist/forEach.es.min.js +1 -1
  71. package/dist/forEach.js +1 -1
  72. package/dist/forEach.min.js +1 -1
  73. package/dist/forEach.mjs +1 -1
  74. package/dist/get.es.js +1 -1
  75. package/dist/get.es.min.js +1 -1
  76. package/dist/get.js +1 -1
  77. package/dist/get.min.js +1 -1
  78. package/dist/get.mjs +1 -1
  79. package/dist/gt.es.js +1 -1
  80. package/dist/gt.es.min.js +1 -1
  81. package/dist/gt.js +1 -1
  82. package/dist/gt.min.js +1 -1
  83. package/dist/gt.mjs +1 -1
  84. package/dist/gte.es.js +1 -1
  85. package/dist/gte.es.min.js +1 -1
  86. package/dist/gte.js +1 -1
  87. package/dist/gte.min.js +1 -1
  88. package/dist/gte.mjs +1 -1
  89. package/dist/lt.es.js +1 -1
  90. package/dist/lt.es.min.js +1 -1
  91. package/dist/lt.js +1 -1
  92. package/dist/lt.min.js +1 -1
  93. package/dist/lt.mjs +1 -1
  94. package/dist/lte.es.js +1 -1
  95. package/dist/lte.es.min.js +1 -1
  96. package/dist/lte.js +1 -1
  97. package/dist/lte.min.js +1 -1
  98. package/dist/lte.mjs +1 -1
  99. package/dist/map.es.js +1 -1
  100. package/dist/map.es.min.js +1 -1
  101. package/dist/map.js +1 -1
  102. package/dist/map.min.js +1 -1
  103. package/dist/map.mjs +1 -1
  104. package/dist/not.es.js +1 -1
  105. package/dist/not.es.min.js +1 -1
  106. package/dist/not.js +1 -1
  107. package/dist/not.min.js +1 -1
  108. package/dist/not.mjs +1 -1
  109. package/dist/omit.es.js +1 -1
  110. package/dist/omit.es.min.js +1 -1
  111. package/dist/omit.js +1 -1
  112. package/dist/omit.min.js +1 -1
  113. package/dist/omit.mjs +1 -1
  114. package/dist/or.es.js +1 -1
  115. package/dist/or.es.min.js +1 -1
  116. package/dist/or.js +1 -1
  117. package/dist/or.min.js +1 -1
  118. package/dist/or.mjs +1 -1
  119. package/dist/pick.es.js +1 -1
  120. package/dist/pick.es.min.js +1 -1
  121. package/dist/pick.js +1 -1
  122. package/dist/pick.min.js +1 -1
  123. package/dist/pick.mjs +1 -1
  124. package/dist/pipe.es.js +1 -1
  125. package/dist/pipe.es.min.js +1 -1
  126. package/dist/pipe.js +1 -1
  127. package/dist/pipe.min.js +1 -1
  128. package/dist/pipe.mjs +1 -1
  129. package/dist/reduce.es.js +1 -1
  130. package/dist/reduce.es.min.js +1 -1
  131. package/dist/reduce.js +1 -1
  132. package/dist/reduce.min.js +1 -1
  133. package/dist/reduce.mjs +1 -1
  134. package/dist/rubico.es.js +57 -19
  135. package/dist/rubico.es.min.js +2 -2
  136. package/dist/rubico.global.js +57 -19
  137. package/dist/rubico.global.min.js +2 -2
  138. package/dist/rubico.js +57 -19
  139. package/dist/rubico.min.js +2 -2
  140. package/dist/rubico.mjs +57 -19
  141. package/dist/set.es.js +1 -1
  142. package/dist/set.es.min.js +1 -1
  143. package/dist/set.js +1 -1
  144. package/dist/set.min.js +1 -1
  145. package/dist/set.mjs +1 -1
  146. package/dist/some.es.js +1 -1
  147. package/dist/some.es.min.js +1 -1
  148. package/dist/some.js +1 -1
  149. package/dist/some.min.js +1 -1
  150. package/dist/some.mjs +1 -1
  151. package/dist/switchCase.es.js +1 -1
  152. package/dist/switchCase.es.min.js +1 -1
  153. package/dist/switchCase.js +1 -1
  154. package/dist/switchCase.min.js +1 -1
  155. package/dist/switchCase.mjs +1 -1
  156. package/dist/tap.es.js +1 -1
  157. package/dist/tap.es.min.js +1 -1
  158. package/dist/tap.js +1 -1
  159. package/dist/tap.min.js +1 -1
  160. package/dist/tap.mjs +1 -1
  161. package/dist/thunkify.es.js +1 -1
  162. package/dist/thunkify.es.min.js +1 -1
  163. package/dist/thunkify.js +1 -1
  164. package/dist/thunkify.min.js +1 -1
  165. package/dist/thunkify.mjs +1 -1
  166. package/dist/transform.es.js +1 -1
  167. package/dist/transform.es.min.js +1 -1
  168. package/dist/transform.js +1 -1
  169. package/dist/transform.min.js +1 -1
  170. package/dist/transform.mjs +1 -1
  171. package/dist/tryCatch.es.js +1 -1
  172. package/dist/tryCatch.es.min.js +1 -1
  173. package/dist/tryCatch.js +1 -1
  174. package/dist/tryCatch.min.js +1 -1
  175. package/dist/tryCatch.mjs +1 -1
  176. package/dist/x/append.es.js +1 -1
  177. package/dist/x/append.es.min.js +1 -1
  178. package/dist/x/append.js +1 -1
  179. package/dist/x/append.min.js +1 -1
  180. package/dist/x/append.mjs +1 -1
  181. package/dist/x/callProp.es.js +1 -1
  182. package/dist/x/callProp.es.min.js +1 -1
  183. package/dist/x/callProp.js +1 -1
  184. package/dist/x/callProp.min.js +1 -1
  185. package/dist/x/callProp.mjs +1 -1
  186. package/dist/x/defaultsDeep.es.js +1 -1
  187. package/dist/x/defaultsDeep.es.min.js +1 -1
  188. package/dist/x/defaultsDeep.js +1 -1
  189. package/dist/x/defaultsDeep.min.js +1 -1
  190. package/dist/x/defaultsDeep.mjs +1 -1
  191. package/dist/x/differenceWith.es.js +1 -1
  192. package/dist/x/differenceWith.es.min.js +1 -1
  193. package/dist/x/differenceWith.js +1 -1
  194. package/dist/x/differenceWith.min.js +1 -1
  195. package/dist/x/differenceWith.mjs +1 -1
  196. package/dist/x/filterOut.es.js +113 -19
  197. package/dist/x/filterOut.es.min.js +2 -2
  198. package/dist/x/filterOut.js +113 -19
  199. package/dist/x/filterOut.min.js +2 -2
  200. package/dist/x/filterOut.mjs +113 -19
  201. package/dist/x/find.es.js +1 -1
  202. package/dist/x/find.es.min.js +1 -1
  203. package/dist/x/find.js +1 -1
  204. package/dist/x/find.min.js +1 -1
  205. package/dist/x/find.mjs +1 -1
  206. package/dist/x/findIndex.es.js +1 -1
  207. package/dist/x/findIndex.es.min.js +1 -1
  208. package/dist/x/findIndex.js +1 -1
  209. package/dist/x/findIndex.min.js +1 -1
  210. package/dist/x/findIndex.mjs +1 -1
  211. package/dist/x/first.es.js +1 -1
  212. package/dist/x/first.es.min.js +1 -1
  213. package/dist/x/first.js +1 -1
  214. package/dist/x/first.min.js +1 -1
  215. package/dist/x/first.mjs +1 -1
  216. package/dist/x/flatten.es.js +1 -1
  217. package/dist/x/flatten.es.min.js +1 -1
  218. package/dist/x/flatten.js +1 -1
  219. package/dist/x/flatten.min.js +1 -1
  220. package/dist/x/flatten.mjs +1 -1
  221. package/dist/x/groupBy.es.js +1 -1
  222. package/dist/x/groupBy.es.min.js +1 -1
  223. package/dist/x/groupBy.js +1 -1
  224. package/dist/x/groupBy.min.js +1 -1
  225. package/dist/x/groupBy.mjs +1 -1
  226. package/dist/x/has.es.js +1 -1
  227. package/dist/x/has.es.min.js +1 -1
  228. package/dist/x/has.js +1 -1
  229. package/dist/x/has.min.js +1 -1
  230. package/dist/x/has.mjs +1 -1
  231. package/dist/x/identity.es.js +1 -1
  232. package/dist/x/identity.es.min.js +1 -1
  233. package/dist/x/identity.js +1 -1
  234. package/dist/x/identity.min.js +1 -1
  235. package/dist/x/identity.mjs +1 -1
  236. package/dist/x/includes.es.js +1 -1
  237. package/dist/x/includes.es.min.js +1 -1
  238. package/dist/x/includes.js +1 -1
  239. package/dist/x/includes.min.js +1 -1
  240. package/dist/x/includes.mjs +1 -1
  241. package/dist/x/isDeepEqual.es.js +1 -1
  242. package/dist/x/isDeepEqual.es.min.js +1 -1
  243. package/dist/x/isDeepEqual.js +1 -1
  244. package/dist/x/isDeepEqual.min.js +1 -1
  245. package/dist/x/isDeepEqual.mjs +1 -1
  246. package/dist/x/isEmpty.es.js +1 -1
  247. package/dist/x/isEmpty.es.min.js +1 -1
  248. package/dist/x/isEmpty.js +1 -1
  249. package/dist/x/isEmpty.min.js +1 -1
  250. package/dist/x/isEmpty.mjs +1 -1
  251. package/dist/x/isEqual.es.js +1 -1
  252. package/dist/x/isEqual.es.min.js +1 -1
  253. package/dist/x/isEqual.js +1 -1
  254. package/dist/x/isEqual.min.js +1 -1
  255. package/dist/x/isEqual.mjs +1 -1
  256. package/dist/x/isFunction.es.js +1 -1
  257. package/dist/x/isFunction.es.min.js +1 -1
  258. package/dist/x/isFunction.js +1 -1
  259. package/dist/x/isFunction.min.js +1 -1
  260. package/dist/x/isFunction.mjs +1 -1
  261. package/dist/x/isIn.es.js +1 -1
  262. package/dist/x/isIn.es.min.js +1 -1
  263. package/dist/x/isIn.js +1 -1
  264. package/dist/x/isIn.min.js +1 -1
  265. package/dist/x/isIn.mjs +1 -1
  266. package/dist/x/isObject.es.js +1 -1
  267. package/dist/x/isObject.es.min.js +1 -1
  268. package/dist/x/isObject.js +1 -1
  269. package/dist/x/isObject.min.js +1 -1
  270. package/dist/x/isObject.mjs +1 -1
  271. package/dist/x/isString.es.js +1 -1
  272. package/dist/x/isString.es.min.js +1 -1
  273. package/dist/x/isString.js +1 -1
  274. package/dist/x/isString.min.js +1 -1
  275. package/dist/x/isString.mjs +1 -1
  276. package/dist/x/keys.es.js +1 -1
  277. package/dist/x/keys.es.min.js +1 -1
  278. package/dist/x/keys.js +1 -1
  279. package/dist/x/keys.min.js +1 -1
  280. package/dist/x/keys.mjs +1 -1
  281. package/dist/x/last.es.js +1 -1
  282. package/dist/x/last.es.min.js +1 -1
  283. package/dist/x/last.js +1 -1
  284. package/dist/x/last.min.js +1 -1
  285. package/dist/x/last.mjs +1 -1
  286. package/dist/x/maxBy.es.js +1 -1
  287. package/dist/x/maxBy.es.min.js +1 -1
  288. package/dist/x/maxBy.js +1 -1
  289. package/dist/x/maxBy.min.js +1 -1
  290. package/dist/x/maxBy.mjs +1 -1
  291. package/dist/x/noop.es.js +1 -1
  292. package/dist/x/noop.es.min.js +1 -1
  293. package/dist/x/noop.js +1 -1
  294. package/dist/x/noop.min.js +1 -1
  295. package/dist/x/noop.mjs +1 -1
  296. package/dist/x/pluck.es.js +1 -1
  297. package/dist/x/pluck.es.min.js +1 -1
  298. package/dist/x/pluck.js +1 -1
  299. package/dist/x/pluck.min.js +1 -1
  300. package/dist/x/pluck.mjs +1 -1
  301. package/dist/x/prepend.es.js +1 -1
  302. package/dist/x/prepend.es.min.js +1 -1
  303. package/dist/x/prepend.js +1 -1
  304. package/dist/x/prepend.min.js +1 -1
  305. package/dist/x/prepend.mjs +1 -1
  306. package/dist/x/size.es.js +1 -1
  307. package/dist/x/size.es.min.js +1 -1
  308. package/dist/x/size.js +1 -1
  309. package/dist/x/size.min.js +1 -1
  310. package/dist/x/size.mjs +1 -1
  311. package/dist/x/trace.es.js +1 -1
  312. package/dist/x/trace.es.min.js +1 -1
  313. package/dist/x/trace.js +1 -1
  314. package/dist/x/trace.min.js +1 -1
  315. package/dist/x/trace.mjs +1 -1
  316. package/dist/x/unionWith.es.js +1 -1
  317. package/dist/x/unionWith.es.min.js +1 -1
  318. package/dist/x/unionWith.js +1 -1
  319. package/dist/x/unionWith.min.js +1 -1
  320. package/dist/x/unionWith.mjs +1 -1
  321. package/dist/x/uniq.es.js +1 -1
  322. package/dist/x/uniq.es.min.js +1 -1
  323. package/dist/x/uniq.js +1 -1
  324. package/dist/x/uniq.min.js +1 -1
  325. package/dist/x/uniq.mjs +1 -1
  326. package/dist/x/unless.es.js +1 -1
  327. package/dist/x/unless.es.min.js +1 -1
  328. package/dist/x/unless.js +1 -1
  329. package/dist/x/unless.min.js +1 -1
  330. package/dist/x/unless.mjs +1 -1
  331. package/dist/x/values.es.js +1 -1
  332. package/dist/x/values.es.min.js +1 -1
  333. package/dist/x/values.js +1 -1
  334. package/dist/x/values.min.js +1 -1
  335. package/dist/x/values.mjs +1 -1
  336. package/dist/x/when.es.js +1 -1
  337. package/dist/x/when.es.min.js +1 -1
  338. package/dist/x/when.js +1 -1
  339. package/dist/x/when.min.js +1 -1
  340. package/dist/x/when.mjs +1 -1
  341. package/eq.js +29 -30
  342. package/es.js +57 -19
  343. package/every.js +14 -20
  344. package/filter.js +38 -75
  345. package/flatMap.js +13 -13
  346. package/forEach.js +8 -8
  347. package/get.js +3 -3
  348. package/gt.js +18 -25
  349. package/gte.js +22 -29
  350. package/index.js +57 -19
  351. package/lt.js +33 -31
  352. package/lte.js +24 -31
  353. package/map.js +32 -35
  354. package/not.js +12 -17
  355. package/or.js +34 -26
  356. package/package.json +1 -1
  357. package/reduce.js +60 -67
  358. package/some.js +11 -34
  359. package/switchCase.js +3 -3
  360. package/thunkify.js +42 -12
  361. 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
- * args Array<any>
101
- * argsOrPromises Array<Promise|any>
100
+ * type SyncOrAsyncPredicate = (...arguments)=>Promise|boolean|any
102
101
  *
103
- * type SyncOrAsyncPredicate = (...args)=>Promise|boolean|any
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
- * Function equivalent to the [Logical OR](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR) operator. Tests arrays of predicate functions, promises, values, or a mix thereof.
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 oneIsLessThanZero = 1 < 0
119
- * const oneIsGreaterThanTwo = 1 > 2
120
- * const threeIsNotEqualToThree = 3 !== 3
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
- * console.log(condition) // false
115
+ *
116
+ * console.log(isOddOrGreaterThan3(2))
117
+ * console.log(isOddOrGreaterThan3(3))
118
+ * console.log(isOddOrGreaterThan3(6))
128
119
  * ```
129
120
  *
130
- * If any predicate functions are provided in the array, `or` returns an aggregate predicate function that returns true for a given set of arguments if any provided predicate functions test true. If any provided predicate functions are asynchronous, the aggregate predicate function becomes asynchronous.
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 condition = await aggregatePredicate(2)
145
- * console.log(condition) // false
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 passed in data argument position are resolved for their values before further execution.
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) // true
162
+ * ]).then(console.log)
155
163
  * ```
156
164
  *
157
165
  * See also:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubico",
3
- "version": "2.11.0",
3
+ "version": "2.12.1",
4
4
  "description": "[a]synchronous functional programming",
5
5
  "author": "Richard Tong",
6
6
  "license": "CFOSS",
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
- * element any,
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
- * initial UnarySyncOrAsyncResolver|any
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 Promise|Foldable, reducer, initial?) -> result Promise|any
39
- * reduce(reducer, initial?)(foldable Foldable) -> result Promise|any
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 a single value.
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 dictated by a provided reducer function, which defines a transformation between the accumulator and a given element of the foldable.
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, element) {
58
- * // nextAccumulator is the result of some operation between accumulator and element
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
- * element any,
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
- * element any
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
- * element any,
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
- * element any
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
- * element any
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
- * element any,
134
+ * item any,
117
135
  * key string,
118
136
  * fold Object
119
137
  * ) -> nextAccumulator Promise|any
120
138
  * ```
121
139
  *
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
- *
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 promise = reduce([1, 2, 3, 4, 5], asyncAdd, 0)
146
- * promise.then(console.log) // 15
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
- * console.log(reduce(array, concatSquares, contrivedInitializer))
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
- * const result = reduce(obj, add)
170
- * console.log(result) // 15
161
+ * console.log(result)
171
162
  * ```
172
163
  *
173
- * For maps, `reduce` iterates over the values of the entries.
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 m = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
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 result = reduce(m, add)
181
- * console.log(result) // 15
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` works for async generators.
179
+ * `reduce` reduces async generators.
185
180
  *
186
181
  * ```javascript [playground]
187
- * const asyncAdd = async (a, b) => a + b
182
+ * const add = (a, b) => a + b
188
183
  *
189
- * const asyncGenerate = async function* () {
184
+ * const generateAsyncNumbers = async function* () {
190
185
  * yield 1; yield 2; yield 3; yield 4; yield 5
191
186
  * }
192
187
  *
193
- * reduce(asyncGenerate(), asyncAdd).then(console.log) // 15
188
+ * const result = await reduce(generateAsyncNumbers(), add)
189
+ *
190
+ * console.log(result)
194
191
  * ```
195
192
  *
196
- * Any promises passed in data argument position are resolved for their values before further execution.
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).then(console.log) // 15
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
- * ```javascript [playground]
207
- * const add = (a, b) => a + b
200
+ * const resultWithPromiseInitialValue = await reduce([1, 2, 3, 4, 5], add, Promise.resolve(0))
208
201
  *
209
- * const promise = reduce([1, 2, 3, 4, 5], add, Promise.resolve(0))
210
- * promise.then(console.log) // 15
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
- * Test a predicate concurrently across all elements of a foldable, returning true if any executions return true.
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
- * console.log(
59
- * some([1, 2, 3, 4, 5], isOdd),
60
- * ) // true
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, // true
79
+ * console.log,
103
80
  * ])
104
81
  * ```
105
82
  *
106
- * Any promises passed in data argument position are resolved for their values before further execution.
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) // false
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 probably not a banana',
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 promise = switchCase(true, [
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
- * promise.then(console.log)
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
- * args Array<any>
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 other function with the arguments. The other function is said to be "thunkified".
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()) // 3
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
- * args Array<any>
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 point = new Point(3, 4)
116
+ * const point1 = new Point(3, 4)
87
117
  *
88
- * const thunk = thunkify.call(point0.distanceTo, point0, point)
118
+ * const thunk = await thunkify.call(point0.distanceTo, point0, Promise.resolve(point1))
89
119
  *
90
120
  * console.log(thunk())
91
121
  * ```