rubico 2.8.6 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (379) hide show
  1. package/README.md +1 -1
  2. package/_internal/FilteringAsyncIterator.js +74 -23
  3. package/_internal/FlatMappingAsyncIterator.js +41 -30
  4. package/_internal/LinkedList.js +54 -0
  5. package/_internal/LinkedList.test.js +34 -0
  6. package/_internal/MappingAsyncIterator.js +65 -15
  7. package/_internal/SerialMappingAsyncIterator.js +79 -0
  8. package/_internal/iteratorFind.js +0 -2
  9. package/_internal/iteratorForEachSeries.js +1 -1
  10. package/_internal/objectFlatten.js +4 -1
  11. package/all.js +7 -8
  12. package/and.js +1 -1
  13. package/assign.js +1 -1
  14. package/compose.js +1 -1
  15. package/curry.js +1 -1
  16. package/dist/Transducer.es.js +1 -1
  17. package/dist/Transducer.es.min.js +1 -1
  18. package/dist/Transducer.js +1 -1
  19. package/dist/Transducer.min.js +1 -1
  20. package/dist/Transducer.mjs +1 -1
  21. package/dist/__.es.js +1 -1
  22. package/dist/__.es.min.js +1 -1
  23. package/dist/__.js +1 -1
  24. package/dist/__.min.js +1 -1
  25. package/dist/__.mjs +1 -1
  26. package/dist/all.es.js +1 -1
  27. package/dist/all.es.min.js +1 -1
  28. package/dist/all.js +1 -1
  29. package/dist/all.min.js +1 -1
  30. package/dist/all.mjs +1 -1
  31. package/dist/always.es.js +1 -1
  32. package/dist/always.es.min.js +1 -1
  33. package/dist/always.js +1 -1
  34. package/dist/always.min.js +1 -1
  35. package/dist/always.mjs +1 -1
  36. package/dist/and.es.js +1 -1
  37. package/dist/and.es.min.js +1 -1
  38. package/dist/and.js +1 -1
  39. package/dist/and.min.js +1 -1
  40. package/dist/and.mjs +1 -1
  41. package/dist/assign.es.js +1 -1
  42. package/dist/assign.es.min.js +1 -1
  43. package/dist/assign.js +1 -1
  44. package/dist/assign.min.js +1 -1
  45. package/dist/assign.mjs +1 -1
  46. package/dist/compose.es.js +1 -1
  47. package/dist/compose.es.min.js +1 -1
  48. package/dist/compose.js +1 -1
  49. package/dist/compose.min.js +1 -1
  50. package/dist/compose.mjs +1 -1
  51. package/dist/curry.es.js +1 -1
  52. package/dist/curry.es.min.js +1 -1
  53. package/dist/curry.js +1 -1
  54. package/dist/curry.min.js +1 -1
  55. package/dist/curry.mjs +1 -1
  56. package/dist/eq.es.js +1 -1
  57. package/dist/eq.es.min.js +1 -1
  58. package/dist/eq.js +1 -1
  59. package/dist/eq.min.js +1 -1
  60. package/dist/eq.mjs +1 -1
  61. package/dist/every.es.js +1 -1
  62. package/dist/every.es.min.js +1 -1
  63. package/dist/every.js +1 -1
  64. package/dist/every.min.js +1 -1
  65. package/dist/every.mjs +1 -1
  66. package/dist/filter.es.js +4 -4
  67. package/dist/filter.es.min.js +2 -2
  68. package/dist/filter.js +4 -4
  69. package/dist/filter.min.js +2 -2
  70. package/dist/filter.mjs +4 -4
  71. package/dist/flatMap.es.js +44 -28
  72. package/dist/flatMap.es.min.js +2 -2
  73. package/dist/flatMap.js +44 -28
  74. package/dist/flatMap.min.js +2 -2
  75. package/dist/flatMap.mjs +44 -28
  76. package/dist/forEach.es.js +6 -6
  77. package/dist/forEach.es.min.js +2 -2
  78. package/dist/forEach.js +6 -6
  79. package/dist/forEach.min.js +2 -2
  80. package/dist/forEach.mjs +6 -6
  81. package/dist/get.es.js +1 -1
  82. package/dist/get.es.min.js +1 -1
  83. package/dist/get.js +1 -1
  84. package/dist/get.min.js +1 -1
  85. package/dist/get.mjs +1 -1
  86. package/dist/gt.es.js +1 -1
  87. package/dist/gt.es.min.js +1 -1
  88. package/dist/gt.js +1 -1
  89. package/dist/gt.min.js +1 -1
  90. package/dist/gt.mjs +1 -1
  91. package/dist/gte.es.js +1 -1
  92. package/dist/gte.es.min.js +1 -1
  93. package/dist/gte.js +1 -1
  94. package/dist/gte.min.js +1 -1
  95. package/dist/gte.mjs +1 -1
  96. package/dist/lt.es.js +1 -1
  97. package/dist/lt.es.min.js +1 -1
  98. package/dist/lt.js +1 -1
  99. package/dist/lt.min.js +1 -1
  100. package/dist/lt.mjs +1 -1
  101. package/dist/lte.es.js +1 -1
  102. package/dist/lte.es.min.js +1 -1
  103. package/dist/lte.js +1 -1
  104. package/dist/lte.min.js +1 -1
  105. package/dist/lte.mjs +1 -1
  106. package/dist/map.es.js +187 -39
  107. package/dist/map.es.min.js +2 -2
  108. package/dist/map.js +187 -39
  109. package/dist/map.min.js +2 -2
  110. package/dist/map.mjs +187 -39
  111. package/dist/not.es.js +1 -1
  112. package/dist/not.es.min.js +1 -1
  113. package/dist/not.js +1 -1
  114. package/dist/not.min.js +1 -1
  115. package/dist/not.mjs +1 -1
  116. package/dist/omit.es.js +1 -1
  117. package/dist/omit.es.min.js +1 -1
  118. package/dist/omit.js +1 -1
  119. package/dist/omit.min.js +1 -1
  120. package/dist/omit.mjs +1 -1
  121. package/dist/or.es.js +1 -1
  122. package/dist/or.es.min.js +1 -1
  123. package/dist/or.js +1 -1
  124. package/dist/or.min.js +1 -1
  125. package/dist/or.mjs +1 -1
  126. package/dist/pick.es.js +1 -1
  127. package/dist/pick.es.min.js +1 -1
  128. package/dist/pick.js +1 -1
  129. package/dist/pick.min.js +1 -1
  130. package/dist/pick.mjs +1 -1
  131. package/dist/pipe.es.js +1 -1
  132. package/dist/pipe.es.min.js +1 -1
  133. package/dist/pipe.js +1 -1
  134. package/dist/pipe.min.js +1 -1
  135. package/dist/pipe.mjs +1 -1
  136. package/dist/reduce.es.js +1 -1
  137. package/dist/reduce.es.min.js +1 -1
  138. package/dist/reduce.js +1 -1
  139. package/dist/reduce.min.js +1 -1
  140. package/dist/reduce.mjs +1 -1
  141. package/dist/rubico.es.js +233 -78
  142. package/dist/rubico.es.min.js +2 -2
  143. package/dist/rubico.global.js +233 -78
  144. package/dist/rubico.global.min.js +2 -2
  145. package/dist/rubico.js +233 -78
  146. package/dist/rubico.min.js +2 -2
  147. package/dist/rubico.mjs +233 -78
  148. package/dist/set.es.js +1 -1
  149. package/dist/set.es.min.js +1 -1
  150. package/dist/set.js +1 -1
  151. package/dist/set.min.js +1 -1
  152. package/dist/set.mjs +1 -1
  153. package/dist/some.es.js +1 -1
  154. package/dist/some.es.min.js +1 -1
  155. package/dist/some.js +1 -1
  156. package/dist/some.min.js +1 -1
  157. package/dist/some.mjs +1 -1
  158. package/dist/switchCase.es.js +1 -1
  159. package/dist/switchCase.es.min.js +1 -1
  160. package/dist/switchCase.js +1 -1
  161. package/dist/switchCase.min.js +1 -1
  162. package/dist/switchCase.mjs +1 -1
  163. package/dist/tap.es.js +1 -1
  164. package/dist/tap.es.min.js +1 -1
  165. package/dist/tap.js +1 -1
  166. package/dist/tap.min.js +1 -1
  167. package/dist/tap.mjs +1 -1
  168. package/dist/thunkify.es.js +1 -1
  169. package/dist/thunkify.es.min.js +1 -1
  170. package/dist/thunkify.js +1 -1
  171. package/dist/thunkify.min.js +1 -1
  172. package/dist/thunkify.mjs +1 -1
  173. package/dist/transform.es.js +1 -1
  174. package/dist/transform.es.min.js +1 -1
  175. package/dist/transform.js +1 -1
  176. package/dist/transform.min.js +1 -1
  177. package/dist/transform.mjs +1 -1
  178. package/dist/tryCatch.es.js +1 -1
  179. package/dist/tryCatch.es.min.js +1 -1
  180. package/dist/tryCatch.js +1 -1
  181. package/dist/tryCatch.min.js +1 -1
  182. package/dist/tryCatch.mjs +1 -1
  183. package/dist/x/append.es.js +1 -1
  184. package/dist/x/append.es.min.js +1 -1
  185. package/dist/x/append.js +1 -1
  186. package/dist/x/append.min.js +1 -1
  187. package/dist/x/append.mjs +1 -1
  188. package/dist/x/callProp.es.js +1 -1
  189. package/dist/x/callProp.es.min.js +1 -1
  190. package/dist/x/callProp.js +1 -1
  191. package/dist/x/callProp.min.js +1 -1
  192. package/dist/x/callProp.mjs +1 -1
  193. package/dist/x/defaultsDeep.es.js +1 -1
  194. package/dist/x/defaultsDeep.es.min.js +1 -1
  195. package/dist/x/defaultsDeep.js +1 -1
  196. package/dist/x/defaultsDeep.min.js +1 -1
  197. package/dist/x/defaultsDeep.mjs +1 -1
  198. package/dist/x/differenceWith.es.js +1 -1
  199. package/dist/x/differenceWith.es.min.js +1 -1
  200. package/dist/x/differenceWith.js +1 -1
  201. package/dist/x/differenceWith.min.js +1 -1
  202. package/dist/x/differenceWith.mjs +1 -1
  203. package/dist/x/filterOut.es.js +4 -4
  204. package/dist/x/filterOut.es.min.js +2 -2
  205. package/dist/x/filterOut.js +4 -4
  206. package/dist/x/filterOut.min.js +2 -2
  207. package/dist/x/filterOut.mjs +4 -4
  208. package/dist/x/find.es.js +1 -3
  209. package/dist/x/find.es.min.js +1 -1
  210. package/dist/x/find.js +1 -3
  211. package/dist/x/find.min.js +1 -1
  212. package/dist/x/find.mjs +1 -3
  213. package/dist/x/findIndex.es.js +1 -1
  214. package/dist/x/findIndex.es.min.js +1 -1
  215. package/dist/x/findIndex.js +1 -1
  216. package/dist/x/findIndex.min.js +1 -1
  217. package/dist/x/findIndex.mjs +1 -1
  218. package/dist/x/first.es.js +1 -1
  219. package/dist/x/first.es.min.js +1 -1
  220. package/dist/x/first.js +1 -1
  221. package/dist/x/first.min.js +1 -1
  222. package/dist/x/first.mjs +1 -1
  223. package/dist/x/flatten.es.js +44 -28
  224. package/dist/x/flatten.es.min.js +2 -2
  225. package/dist/x/flatten.js +44 -28
  226. package/dist/x/flatten.min.js +2 -2
  227. package/dist/x/flatten.mjs +44 -28
  228. package/dist/x/groupBy.es.js +1 -1
  229. package/dist/x/groupBy.es.min.js +1 -1
  230. package/dist/x/groupBy.js +1 -1
  231. package/dist/x/groupBy.min.js +1 -1
  232. package/dist/x/groupBy.mjs +1 -1
  233. package/dist/x/has.es.js +1 -1
  234. package/dist/x/has.es.min.js +1 -1
  235. package/dist/x/has.js +1 -1
  236. package/dist/x/has.min.js +1 -1
  237. package/dist/x/has.mjs +1 -1
  238. package/dist/x/identity.es.js +1 -1
  239. package/dist/x/identity.es.min.js +1 -1
  240. package/dist/x/identity.js +1 -1
  241. package/dist/x/identity.min.js +1 -1
  242. package/dist/x/identity.mjs +1 -1
  243. package/dist/x/includes.es.js +1 -1
  244. package/dist/x/includes.es.min.js +1 -1
  245. package/dist/x/includes.js +1 -1
  246. package/dist/x/includes.min.js +1 -1
  247. package/dist/x/includes.mjs +1 -1
  248. package/dist/x/isDeepEqual.es.js +1 -1
  249. package/dist/x/isDeepEqual.es.min.js +1 -1
  250. package/dist/x/isDeepEqual.js +1 -1
  251. package/dist/x/isDeepEqual.min.js +1 -1
  252. package/dist/x/isDeepEqual.mjs +1 -1
  253. package/dist/x/isEmpty.es.js +1 -1
  254. package/dist/x/isEmpty.es.min.js +1 -1
  255. package/dist/x/isEmpty.js +1 -1
  256. package/dist/x/isEmpty.min.js +1 -1
  257. package/dist/x/isEmpty.mjs +1 -1
  258. package/dist/x/isEqual.es.js +1 -1
  259. package/dist/x/isEqual.es.min.js +1 -1
  260. package/dist/x/isEqual.js +1 -1
  261. package/dist/x/isEqual.min.js +1 -1
  262. package/dist/x/isEqual.mjs +1 -1
  263. package/dist/x/isFunction.es.js +1 -1
  264. package/dist/x/isFunction.es.min.js +1 -1
  265. package/dist/x/isFunction.js +1 -1
  266. package/dist/x/isFunction.min.js +1 -1
  267. package/dist/x/isFunction.mjs +1 -1
  268. package/dist/x/isIn.es.js +1 -1
  269. package/dist/x/isIn.es.min.js +1 -1
  270. package/dist/x/isIn.js +1 -1
  271. package/dist/x/isIn.min.js +1 -1
  272. package/dist/x/isIn.mjs +1 -1
  273. package/dist/x/isObject.es.js +1 -1
  274. package/dist/x/isObject.es.min.js +1 -1
  275. package/dist/x/isObject.js +1 -1
  276. package/dist/x/isObject.min.js +1 -1
  277. package/dist/x/isObject.mjs +1 -1
  278. package/dist/x/isString.es.js +1 -1
  279. package/dist/x/isString.es.min.js +1 -1
  280. package/dist/x/isString.js +1 -1
  281. package/dist/x/isString.min.js +1 -1
  282. package/dist/x/isString.mjs +1 -1
  283. package/dist/x/keys.es.js +1 -1
  284. package/dist/x/keys.es.min.js +1 -1
  285. package/dist/x/keys.js +1 -1
  286. package/dist/x/keys.min.js +1 -1
  287. package/dist/x/keys.mjs +1 -1
  288. package/dist/x/last.es.js +1 -1
  289. package/dist/x/last.es.min.js +1 -1
  290. package/dist/x/last.js +1 -1
  291. package/dist/x/last.min.js +1 -1
  292. package/dist/x/last.mjs +1 -1
  293. package/dist/x/maxBy.es.js +1 -1
  294. package/dist/x/maxBy.es.min.js +1 -1
  295. package/dist/x/maxBy.js +1 -1
  296. package/dist/x/maxBy.min.js +1 -1
  297. package/dist/x/maxBy.mjs +1 -1
  298. package/dist/x/noop.es.js +1 -1
  299. package/dist/x/noop.es.min.js +1 -1
  300. package/dist/x/noop.js +1 -1
  301. package/dist/x/noop.min.js +1 -1
  302. package/dist/x/noop.mjs +1 -1
  303. package/dist/x/pluck.es.js +187 -39
  304. package/dist/x/pluck.es.min.js +2 -2
  305. package/dist/x/pluck.js +187 -39
  306. package/dist/x/pluck.min.js +2 -2
  307. package/dist/x/pluck.mjs +187 -39
  308. package/dist/x/prepend.es.js +1 -1
  309. package/dist/x/prepend.es.min.js +1 -1
  310. package/dist/x/prepend.js +1 -1
  311. package/dist/x/prepend.min.js +1 -1
  312. package/dist/x/prepend.mjs +1 -1
  313. package/dist/x/size.es.js +1 -1
  314. package/dist/x/size.es.min.js +1 -1
  315. package/dist/x/size.js +1 -1
  316. package/dist/x/size.min.js +1 -1
  317. package/dist/x/size.mjs +1 -1
  318. package/dist/x/trace.es.js +1 -1
  319. package/dist/x/trace.es.min.js +1 -1
  320. package/dist/x/trace.js +1 -1
  321. package/dist/x/trace.min.js +1 -1
  322. package/dist/x/trace.mjs +1 -1
  323. package/dist/x/unionWith.es.js +1 -1
  324. package/dist/x/unionWith.es.min.js +1 -1
  325. package/dist/x/unionWith.js +1 -1
  326. package/dist/x/unionWith.min.js +1 -1
  327. package/dist/x/unionWith.mjs +1 -1
  328. package/dist/x/uniq.es.js +1 -1
  329. package/dist/x/uniq.es.min.js +1 -1
  330. package/dist/x/uniq.js +1 -1
  331. package/dist/x/uniq.min.js +1 -1
  332. package/dist/x/uniq.mjs +1 -1
  333. package/dist/x/unless.es.js +1 -1
  334. package/dist/x/unless.es.min.js +1 -1
  335. package/dist/x/unless.js +1 -1
  336. package/dist/x/unless.min.js +1 -1
  337. package/dist/x/unless.mjs +1 -1
  338. package/dist/x/values.es.js +1 -1
  339. package/dist/x/values.es.min.js +1 -1
  340. package/dist/x/values.js +1 -1
  341. package/dist/x/values.min.js +1 -1
  342. package/dist/x/values.mjs +1 -1
  343. package/dist/x/when.es.js +1 -1
  344. package/dist/x/when.es.min.js +1 -1
  345. package/dist/x/when.js +1 -1
  346. package/dist/x/when.min.js +1 -1
  347. package/dist/x/when.mjs +1 -1
  348. package/eq.js +2 -2
  349. package/es.js +233 -78
  350. package/every.js +2 -2
  351. package/filter.js +22 -23
  352. package/flatMap.js +61 -54
  353. package/forEach.js +33 -56
  354. package/get.js +5 -3
  355. package/gt.js +2 -2
  356. package/gte.js +2 -2
  357. package/index.js +233 -78
  358. package/lt.js +2 -2
  359. package/lte.js +2 -2
  360. package/map.js +117 -154
  361. package/monad/README.md +1 -1
  362. package/not.js +1 -1
  363. package/omit.js +22 -19
  364. package/or.js +1 -1
  365. package/package.json +1 -1
  366. package/pick.js +14 -11
  367. package/pipe.js +1 -1
  368. package/reduce.js +1 -1
  369. package/set.js +17 -18
  370. package/some.js +2 -2
  371. package/switchCase.js +12 -4
  372. package/tap.js +6 -4
  373. package/transform.js +1 -1
  374. package/tryCatch.js +1 -1
  375. package/x/defaultsDeep.js +1 -1
  376. package/x/defaultsDeep.test.js +1 -1
  377. package/_internal/NextIteration.js +0 -12
  378. package/_internal/generatorFunctionFilter.js +0 -28
  379. package/_internal/iterationMap.js +0 -27
package/es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Rubico v2.8.6
2
+ * Rubico v2.10.0
3
3
  * https://rubico.land/
4
4
  *
5
5
  * © Richard Yufei Tong, King of Software
@@ -601,26 +601,167 @@ const MappingIterator = (iterator, mapper) => ({
601
601
  },
602
602
  })
603
603
 
604
- const NextIteration = value => ({ value, done: false })
604
+ const promiseRace = Promise.race.bind(Promise)
605
605
 
606
- const symbolAsyncIterator = Symbol.asyncIterator
606
+ class LinkedList {
607
+ constructor() {
608
+ this.first = null
609
+ this.last = null
610
+ this.length = 0
611
+ }
607
612
 
608
- const MappingAsyncIterator = (asyncIterator, mapper) => ({
609
- [symbolAsyncIterator]() {
610
- return this
611
- },
612
- async next() {
613
- const iteration = await asyncIterator.next()
614
- if (iteration.done) {
615
- return iteration
613
+ // popFirst() -> firstValue any
614
+ popFirst() {
615
+ const first = this.first
616
+
617
+ if (first == null) {
618
+ return undefined
619
+ }
620
+
621
+ if (first.next) {
622
+ this.first = first.next
623
+ } else {
624
+ this.first = null
625
+ }
626
+
627
+ this.length -= 1
628
+
629
+ return first.value
630
+ }
631
+
632
+ // append(value any) -> undefined
633
+ append(value) {
634
+ const node = { value }
635
+ if (this.first == null) {
636
+ this.first = node
637
+ }
638
+
639
+ if (this.last == null) {
640
+ this.last = node
641
+ } else {
642
+ this.last.next = node
643
+ this.last = node
616
644
  }
617
- const mapped = mapper(iteration.value)
618
- return isPromise(mapped)
619
- ? mapped.then(NextIteration)
620
- : { value: mapped, done: false }
645
+
646
+ this.length += 1
621
647
  }
648
+
649
+ }
650
+
651
+ const symbolAsyncIterator = Symbol.asyncIterator
652
+
653
+ const arrayPush = function (array, value) {
654
+ array.push(value)
655
+ return array
656
+ }
657
+
658
+ const sleep = time => new Promise(resolve => {
659
+ setTimeout(resolve, time)
622
660
  })
623
661
 
662
+ const MappingAsyncIterator = (asyncIterator, mapper) => {
663
+ const buffer = new LinkedList()
664
+
665
+ let index = -1
666
+ let consumingAsyncIterator = false
667
+ let isAsyncIteratorDone = false
668
+
669
+ return {
670
+ [symbolAsyncIterator]() {
671
+ return this
672
+ },
673
+
674
+ // _consumeAsyncIterator() -> Promise<>
675
+ async _consumeAsyncIterator() {
676
+ for await (const item of asyncIterator) {
677
+ index += 1
678
+ const mappedItem = mapper(item)
679
+ buffer.append(mappedItem)
680
+ }
681
+ isAsyncIteratorDone = true
682
+ },
683
+
684
+
685
+ async next() {
686
+ if (!consumingAsyncIterator) {
687
+ this._consumeAsyncIterator()
688
+ consumingAsyncIterator = true
689
+ }
690
+
691
+ while (!isAsyncIteratorDone) {
692
+ if (buffer.length > 0) {
693
+ let value = buffer.popFirst()
694
+ if (isPromise(value)) {
695
+ value = await value
696
+ }
697
+ return { value, done: false }
698
+ }
699
+ await sleep(10)
700
+ }
701
+
702
+ if (buffer.length > 0) {
703
+ let value = buffer.popFirst()
704
+ if (isPromise(value)) {
705
+ value = await value
706
+ }
707
+ return { value, done: false }
708
+ }
709
+
710
+ return { value: undefined, done: true }
711
+ },
712
+
713
+ }
714
+ }
715
+
716
+ const SerialMappingAsyncIterator = (asyncIterator, mapper) => {
717
+ const buffer = new LinkedList()
718
+
719
+ let index = -1
720
+ let consumingAsyncIterator = false
721
+ let isAsyncIteratorDone = false
722
+
723
+ return {
724
+ [symbolAsyncIterator]() {
725
+ return this
726
+ },
727
+
728
+ // _consumeAsyncIterator() -> Promise<>
729
+ async _consumeAsyncIterator() {
730
+ for await (const item of asyncIterator) {
731
+ index += 1
732
+ let mappedItem = mapper(item)
733
+ if (isPromise(mappedItem)) {
734
+ mappedItem = await mappedItem
735
+ }
736
+ buffer.append(mappedItem)
737
+ }
738
+ isAsyncIteratorDone = true
739
+ },
740
+
741
+
742
+ async next() {
743
+ if (!consumingAsyncIterator) {
744
+ this._consumeAsyncIterator()
745
+ consumingAsyncIterator = true
746
+ }
747
+
748
+ while (!isAsyncIteratorDone) {
749
+ if (buffer.length > 0) {
750
+ return { value: buffer.popFirst(), done: false }
751
+ }
752
+ await sleep(10)
753
+ }
754
+
755
+ if (buffer.length > 0) {
756
+ return { value: buffer.popFirst(), done: false }
757
+ }
758
+
759
+ return { value: undefined, done: true }
760
+ },
761
+
762
+ }
763
+ }
764
+
624
765
  const isObject = value => {
625
766
  if (value == null) {
626
767
  return false
@@ -866,8 +1007,6 @@ const tapSync = func => function tapping(...args) {
866
1007
  return args[0]
867
1008
  }
868
1009
 
869
- const promiseRace = Promise.race.bind(Promise)
870
-
871
1010
  const arrayMapPoolAsync = async function (
872
1011
  array, f, concurrencyLimit, result, index, promises,
873
1012
  ) {
@@ -1190,9 +1329,6 @@ const _map = function (value, f) {
1190
1329
  if (typeof value.then == 'function') {
1191
1330
  return value.then(f)
1192
1331
  }
1193
- if (typeof value.map == 'function') {
1194
- return value.map(f)
1195
- }
1196
1332
  if (typeof value == 'string' || value.constructor == String) {
1197
1333
  return stringMap(value, f)
1198
1334
  }
@@ -1208,6 +1344,9 @@ const _map = function (value, f) {
1208
1344
  if (typeof value[symbolAsyncIterator] == 'function') {
1209
1345
  return MappingAsyncIterator(value[symbolAsyncIterator](), f)
1210
1346
  }
1347
+ if (typeof value.map == 'function') {
1348
+ return value.map(f)
1349
+ }
1211
1350
  if (value.constructor == Object) {
1212
1351
  return objectMap(value, f)
1213
1352
  }
@@ -1246,27 +1385,36 @@ map.entries = function mapEntries(arg0, arg1) {
1246
1385
  : _mapEntries(arg0, arg1)
1247
1386
  }
1248
1387
 
1249
- const _mapSeries = function (collection, f) {
1250
- if (isArray(collection)) {
1251
- return arrayMapSeries(collection, f)
1388
+ const _mapSeries = function (functor, f) {
1389
+ if (isArray(functor)) {
1390
+ return arrayMapSeries(functor, f)
1252
1391
  }
1253
- if (collection == null) {
1254
- throw new TypeError(`invalid collection ${collection}`)
1392
+ if (functor == null) {
1393
+ throw new TypeError(`invalid functor ${functor}`)
1255
1394
  }
1256
1395
 
1257
- if (typeof collection == 'string' || collection.constructor == String) {
1258
- return stringMapSeries(collection, f)
1396
+ if (typeof functor == 'string' || functor.constructor == String) {
1397
+ return stringMapSeries(functor, f)
1259
1398
  }
1260
- if (collection.constructor == Set) {
1261
- return setMapSeries(collection, f)
1399
+ if (functor.constructor == Set) {
1400
+ return setMapSeries(functor, f)
1262
1401
  }
1263
- if (collection.constructor == Map) {
1264
- return mapMapSeries(collection, f)
1402
+ if (functor.constructor == Map) {
1403
+ return mapMapSeries(functor, f)
1265
1404
  }
1266
- if (collection.constructor == Object) {
1267
- return objectMapSeries(collection, f)
1405
+ if (typeof functor[symbolIterator] == 'function') {
1406
+ return MappingIterator(functor[symbolIterator](), f)
1268
1407
  }
1269
- throw new TypeError(`invalid collection ${collection}`)
1408
+ if (typeof functor[symbolAsyncIterator] == 'function') {
1409
+ return SerialMappingAsyncIterator(functor[symbolAsyncIterator](), f)
1410
+ }
1411
+ if (typeof functor.map == 'function') {
1412
+ return functor.map(f)
1413
+ }
1414
+ if (functor.constructor == Object) {
1415
+ return objectMapSeries(functor, f)
1416
+ }
1417
+ throw new TypeError(`invalid functor ${functor}`)
1270
1418
  }
1271
1419
 
1272
1420
  map.series = function mapSeries(arg0, arg1) {
@@ -1483,15 +1631,15 @@ const _filter = function (value, predicate) {
1483
1631
  if (value.constructor == Map) {
1484
1632
  return mapFilter(value, predicate)
1485
1633
  }
1486
- if (typeof value.filter == 'function') {
1487
- return value.filter(predicate)
1488
- }
1489
1634
  if (typeof value[symbolIterator] == 'function') {
1490
1635
  return FilteringIterator(value[symbolIterator](), predicate)
1491
1636
  }
1492
1637
  if (typeof value[symbolAsyncIterator] == 'function') {
1493
1638
  return FilteringAsyncIterator(value[symbolAsyncIterator](), predicate)
1494
1639
  }
1640
+ if (typeof value.filter == 'function') {
1641
+ return value.filter(predicate)
1642
+ }
1495
1643
  if (value.constructor == Object) {
1496
1644
  return objectFilter(value, predicate)
1497
1645
  }
@@ -1938,11 +2086,6 @@ const transform = function (...args) {
1938
2086
  return _transform(args[0], args[1], args[2])
1939
2087
  }
1940
2088
 
1941
- const arrayPush = function (array, value) {
1942
- array.push(value)
1943
- return array
1944
- }
1945
-
1946
2089
  const FlatMappingIterator = function (iterator, flatMapper) {
1947
2090
  let buffer = [],
1948
2091
  bufferIndex = 0
@@ -1977,13 +2120,12 @@ const FlatMappingIterator = function (iterator, flatMapper) {
1977
2120
  }
1978
2121
  }
1979
2122
 
1980
- const sleep = time => new Promise(resolve => {
1981
- setTimeout(resolve, time)
1982
- })
1983
-
1984
2123
  const FlatMappingAsyncIterator = function (asyncIterator, flatMapper) {
1985
- const buffer = [],
1986
- promises = new Set()
2124
+ const buffer = []
2125
+ const promises = new Set()
2126
+
2127
+ let consumingAsyncIterator = false
2128
+ let isAsyncIteratorDone = false
1987
2129
 
1988
2130
  return {
1989
2131
  isAsyncIteratorDone: false,
@@ -1994,38 +2136,48 @@ const FlatMappingAsyncIterator = function (asyncIterator, flatMapper) {
1994
2136
  return '[object FlatMappingAsyncIterator]'
1995
2137
  },
1996
2138
 
1997
-
1998
- async next() {
1999
- while (
2000
- !this.isAsyncIteratorDone || buffer.length > 0 || promises.size > 0
2001
- ) {
2002
- if (!this.isAsyncIteratorDone) {
2003
- const { value, done } = await asyncIterator.next()
2004
- if (done) {
2005
- this.isAsyncIteratorDone = done
2006
- } else {
2007
- const monad = flatMapper(value)
2008
- if (isPromise(monad)) {
2009
- const bufferLoading =
2010
- monad.then(curry3(genericReduce, __, arrayPush, buffer))
2011
- const promise = bufferLoading.then(() => promises.delete(promise))
2012
- promises.add(promise)
2013
- } else {
2014
- const bufferLoading = genericReduce(monad, arrayPush, buffer)
2015
- if (isPromise(bufferLoading)) {
2016
- const promise = bufferLoading.then(() => promises.delete(promise))
2017
- promises.add(promise)
2018
- }
2019
- }
2139
+ // _consumeAsyncIterator() -> Promise<>
2140
+ async _consumeAsyncIterator() {
2141
+ for await (const item of asyncIterator) {
2142
+ const monad = flatMapper(item)
2143
+ if (isPromise(monad)) {
2144
+ const bufferLoading =
2145
+ monad.then(curry3(genericReduce, __, arrayPush, buffer))
2146
+ const promise = bufferLoading.then(() => promises.delete(promise))
2147
+ promises.add(promise)
2148
+ } else {
2149
+ const bufferLoading = genericReduce(monad, arrayPush, buffer)
2150
+ if (isPromise(bufferLoading)) {
2151
+ const promise = bufferLoading.then(() => promises.delete(promise))
2152
+ promises.add(promise)
2020
2153
  }
2021
2154
  }
2155
+ }
2156
+ isAsyncIteratorDone = true
2157
+ },
2158
+
2159
+
2160
+ async next() {
2161
+ if (!consumingAsyncIterator) {
2162
+ this._consumeAsyncIterator()
2163
+ consumingAsyncIterator = true
2164
+ }
2165
+
2166
+ while (!isAsyncIteratorDone || promises.size > 0) {
2022
2167
  if (buffer.length > 0) {
2023
2168
  return { value: buffer.shift(), done: false }
2024
2169
  }
2025
2170
  if (promises.size > 0) {
2026
- await promiseRace([sleep(1000), ...promises])
2171
+ await promiseRace(promises)
2172
+ } else {
2173
+ await sleep(10)
2027
2174
  }
2028
2175
  }
2176
+
2177
+ if (buffer.length > 0) {
2178
+ return { value: buffer.shift(), done: false }
2179
+ }
2180
+
2029
2181
  return { value: undefined, done: true }
2030
2182
  },
2031
2183
  }
@@ -2121,9 +2273,12 @@ const objectFlatten = function (object) {
2121
2273
 
2122
2274
  for (const key in object) {
2123
2275
  const element = object[key]
2276
+
2124
2277
  if (element == null) {
2125
2278
  continue
2126
- } else if (typeof element[symbolIterator] == 'function') {
2279
+ }
2280
+
2281
+ if (typeof element[symbolIterator] == 'function') {
2127
2282
  for (const monadElement of element) {
2128
2283
  objectAssign(result, monadElement)
2129
2284
  }
@@ -2384,7 +2539,7 @@ const _iteratorForEachSeriesAsync = async function (iterator, callback) {
2384
2539
 
2385
2540
  const iteratorForEachSeries = function (iterator, callback) {
2386
2541
  let iteration = iterator.next()
2387
- while (!iterator.done) {
2542
+ while (!iteration.done) {
2388
2543
  const operation = callback(iteration.value)
2389
2544
  if (isPromise(operation)) {
2390
2545
  return operation
@@ -2414,16 +2569,16 @@ const _forEach = function (collection, callback) {
2414
2569
  if (collection == null) {
2415
2570
  return collection
2416
2571
  }
2417
- if (typeof collection.forEach == 'function') {
2418
- collection.forEach(callback)
2419
- return collection
2420
- }
2421
2572
  if (typeof collection[symbolIterator] == 'function') {
2422
2573
  return iteratorForEach(collection[symbolIterator](), callback)
2423
2574
  }
2424
2575
  if (typeof collection[symbolAsyncIterator] == 'function') {
2425
2576
  return asyncIteratorForEach(collection[symbolAsyncIterator](), callback)
2426
2577
  }
2578
+ if (typeof collection.forEach == 'function') {
2579
+ collection.forEach(callback)
2580
+ return collection
2581
+ }
2427
2582
  if (collection.constructor == Object) {
2428
2583
  return objectForEach(collection, callback)
2429
2584
  }
package/every.js CHANGED
@@ -84,7 +84,7 @@ const _every = function (collection, predicate) {
84
84
  * every(asyncNumbers(), async number => number < 6).then(console.log) // true
85
85
  * ```
86
86
  *
87
- * `every` supports a lazy API for composability.
87
+ * `every` supports a lazy interface for composability.
88
88
  *
89
89
  * ```javascript [playground]
90
90
  * pipe([1, 2, 3], [
@@ -93,7 +93,7 @@ const _every = function (collection, predicate) {
93
93
  * ])
94
94
  * ```
95
95
  *
96
- * Any promises passed in argument position are resolved for their values before further execution.
96
+ * Any promises passed in data argument position are resolved for their values before further execution.
97
97
  *
98
98
  * ```javascript [playground]
99
99
  * every(Promise.resolve([1, 2, 3, 4, 5]), n => n < 6).then(console.log) // true
package/filter.js CHANGED
@@ -70,15 +70,15 @@ const _filter = function (value, predicate) {
70
70
  if (value.constructor == Map) {
71
71
  return mapFilter(value, predicate)
72
72
  }
73
- if (typeof value.filter == 'function') {
74
- return value.filter(predicate)
75
- }
76
73
  if (typeof value[symbolIterator] == 'function') {
77
74
  return FilteringIterator(value[symbolIterator](), predicate)
78
75
  }
79
76
  if (typeof value[symbolAsyncIterator] == 'function') {
80
77
  return FilteringAsyncIterator(value[symbolAsyncIterator](), predicate)
81
78
  }
79
+ if (typeof value.filter == 'function') {
80
+ return value.filter(predicate)
81
+ }
82
82
  if (value.constructor == Object) {
83
83
  return objectFilter(value, predicate)
84
84
  }
@@ -96,14 +96,14 @@ const _filter = function (value, predicate) {
96
96
  * value any,
97
97
  * indexOrKey number|string|any,
98
98
  * filterable Filterable,
99
- * )=>(condition Promise|boolean)
99
+ * )=>(booleanResult Promise|boolean)
100
100
  *
101
- * filter(filterable Promise|Filterable, predicate SyncOrAsyncPredicate) -> result Promise|Filterable
102
- * filter(predicate SyncOrAsyncPredicate)(filterable Filterable) -> result Promise|Filterable
101
+ * filter(filterable Promise|Filterable, predicate SyncOrAsyncPredicate) -> filteredFilterable Promise|Filterable
102
+ * filter(predicate SyncOrAsyncPredicate)(filterable Filterable) -> filteredFilterable Promise|Filterable
103
103
  * ```
104
104
  *
105
105
  * @description
106
- * Filters out elements from a filterable. Returns a filterable of the same type. The order of the elements in the filterable is preserved.
106
+ * Filters out items from a filterable, returning a filterable of the same type. The order of the items of the filterable is preserved.
107
107
  *
108
108
  * The following data types are considered to be filterables:
109
109
  * * `array`
@@ -114,12 +114,12 @@ const _filter = function (value, predicate) {
114
114
  * * `object with .filter method`
115
115
  * * `object`
116
116
  *
117
- * The filtering operation is defined by a given predicate function. The predicate function dictates whether a given element from the filterable should be included in the returned filterable.
117
+ * The filtering operation is defined by a given predicate function. The predicate function dictates whether a given item from the filterable should be included in the returned filterable.
118
118
  *
119
119
  * ```javascript
120
- * const predicate = function (element) {
121
- * // condition is the boolean result of the predicate test on element
122
- * return condition
120
+ * const predicate = function (item) {
121
+ * // booleanResult is the boolean result of the predicate test on item
122
+ * return booleanResult
123
123
  * }
124
124
  * ```
125
125
  *
@@ -127,48 +127,47 @@ const _filter = function (value, predicate) {
127
127
  *
128
128
  * If the filterable is an array:
129
129
  * ```coffeescript [specscript]
130
- * predicate(element any, index number, filt Array) -> condition Promise|boolean|any
130
+ * predicate(item any, index number, filterable Array) -> booleanResult Promise|boolean|any
131
131
  * ```
132
132
  *
133
133
  * If the filterable is a set:
134
134
  * ```coffeescript [specscript]
135
- * predicate(element any, element any, filt Set) -> condition Promise|boolean|any
135
+ * predicate(item any, item any, filterable Set) -> booleanResult Promise|boolean|any
136
136
  * ```
137
137
  *
138
138
  * If the filterable is a map:
139
139
  * ```coffeescript [specscript]
140
- * predicate(element any, key any, filt Map) -> condition Promise|boolean|any
140
+ * predicate(item any, key any, filterable Map) -> booleanResult Promise|boolean|any
141
141
  * ```
142
142
  *
143
143
  * If the filterable is a generator:
144
144
  * ```coffeescript [specscript]
145
- * predicate(element any) -> condition Promise|boolean|any
145
+ * predicate(item any) -> booleanResult Promise|boolean|any
146
146
  * ```
147
147
  *
148
148
  * If the filterable is an async generator:
149
149
  * ```coffeescript [specscript]
150
- * predicate(element any) -> condition Promise|boolean|any
150
+ * predicate(item any) -> booleanResult Promise|boolean|any
151
151
  * ```
152
152
  *
153
153
  * If the filterable is an object with a `.filter` method, the predicate function signature is defined externally.
154
154
  *
155
155
  * If the filterable is a plain object:
156
156
  * ```coffeescript [specscript]
157
- * predicate(element any, key string, filt Object) -> condition Promise|boolean|any
157
+ * predicate(item any, key string, filterable Object) -> booleanResult Promise|boolean|any
158
158
  * ```
159
159
  *
160
- * `filter` works for arrays.
161
- *
162
160
  * ```javascript [playground]
163
161
  * const isOdd = number => number % 2 == 1
164
162
  *
165
163
  * const array = [1, 2, 3, 4, 5]
166
164
  *
167
- * const result = filter(array, isOdd)
168
- * console.log(result) // [1, 3, 5]
165
+ * const filteredArray = filter(array, isOdd)
166
+ *
167
+ * console.log(filteredArray)
169
168
  * ```
170
169
  *
171
- * If the predicate is asynchronous, the returned promise is concurrently resolved for its boolean condition before continuing with the filtering operation.
170
+ * If the predicate is asynchronous, it is executed concurrently.
172
171
  *
173
172
  * ```javascript [playground]
174
173
  * const asyncIsOdd = async number => number % 2 == 1
@@ -256,7 +255,7 @@ const _filter = function (value, predicate) {
256
255
  * }
257
256
  * ```
258
257
  *
259
- * Any promises passed in argument position are resolved for their values before further execution.
258
+ * Any promises passed in data argument position are resolved for their values before further execution.
260
259
  *
261
260
  * ```javascript [playground]
262
261
  * const isOdd = number => number % 2 == 1