🆙 Add cms i using 🆙

This commit is contained in:
Remco
2025-11-25 22:42:56 +01:00
parent 94704e0925
commit d44196149e
35591 changed files with 3601123 additions and 0 deletions
+291
View File
@@ -0,0 +1,291 @@
<p align="center">
<img alt="aigle" src="https://raw.githubusercontent.com/suguru03/aigle/gh-pages/images/logo.png" width=500>
</p>
<p align="center">
<a href="https://www.npmjs.com/package/aigle"><img alt="npm" src="https://img.shields.io/npm/v/aigle.svg"></a>
<a href="https://circleci.com/gh/suguru03/aigle/tree/master"><img alt="CircleCI Status" src="https://img.shields.io/circleci/project/github/suguru03/aigle/master.svg"></a>
<a href="https://codecov.io/gh/suguru03/aigle"><img alt="Coverage Status" src="https://img.shields.io/codecov/c/github/suguru03/aigle/master.svg"></a>
</p>
Aigle is an ideal promise library which is faster and more efficient than other libraries.
On top of being an impressive benchmark exercise, it is a production-ready library that implements the Promise A+ standard.
Also it has a lot of [async](https://github.com/caolan/async) style functions, you can start using `Promise` easily.
- [benchmark](https://github.com/suguru03/bluebird/tree/aigle/benchmark)
- [What makes Aigle fast](https://hackernoon.com/how-to-make-the-fastest-promise-library-f632fd69f3cb)
Usage
--
### Node.js
```sh
npm install --save aigle
```
```js
const Aigle = require('aigle');
```
```js
const each = require('aigle/each');
```
### TypeScript
```ts
import Aigle from 'aigle';
```
```ts
import { Aigle } from 'aigle';
```
#### Async/Await
```js
global.Promise = Aigle;
```
```js
async function getUsers(ids) {
const users = await Promise.map(ids, getUser);
const targets = await Promise.filter(users, filterUser);
return targets;
}
async function getUsers(ids) {
return await Promise.map(ids, getUser)
.filter(filterUser);
}
```
#### Convert synchronous functions to asynchronous functions
```js
Aigle.mixin(require('lodash'));
return Aigle.map([1.1, 1.4, 2.2], n => Aigle.delay(10, n * 2)) // [2.2, 2.8, 4.4]
.uniqBy(n => Aigle.delay(10, Math.floor(n))) // [2.2, 4.4]
.sum() // 6.6
.times() // [0, 1, 2, 3, 4, 5];
.then(value => console.log(value)); // [0, 1, 2, 3, 4, 5];
```
### browser
Recommend to use [webpack](https://github.com/webpack/webpack), [browserify](https://github.com/substack/node-browserify), [Rollup](https://github.com/rollup/rollup) or any bundling tool.
#### or prebuilt scripts from [here](https://github.com/suguru03/aigle/tree/master/dist/).
This will expose to global as `window.Promise`.
```html
<script src="dist/aigle.min.js"></script>
```
```js
window.Promise;
```
Functions
--
### Core
#### prototype functions
- [`then`](https://suguru03.github.io/aigle/docs/Aigle.html#then)
- [`spread`](https://suguru03.github.io/aigle/docs/Aigle.html#spread)
- [`catch`](https://suguru03.github.io/aigle/docs/Aigle.html#catch)
- [`finally`](https://suguru03.github.io/aigle/docs/Aigle.html#finally)
- [`cancel`](https://suguru03.github.io/aigle/docs/Aigle.html#cancel)
- [`toString`](https://suguru03.github.io/aigle/docs/Aigle.html#toString)
#### class functions
- [`Promise.resolve`](https://suguru03.github.io/aigle/docs/global.html#resolve)
- [`Promise.reject`](https://suguru03.github.io/aigle/docs/global.html#reject)
- [`Promise.attempt`](https://suguru03.github.io/aigle/docs/global.html#attempt)
- [`Promise.try`](https://suguru03.github.io/aigle/docs/global.html#try) -> [`Promise.attempt`](https://suguru03.github.io/aigle/docs/global.html#try)
- [`Promise.join`](https://suguru03.github.io/aigle/docs/global.html#join)
### Collections
#### prototype functions
- [`concat`](https://suguru03.github.io/aigle/docs/Aigle.html#concat)
- [`concatSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#concatSeries)
- [`concatLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#concatLimit)
- [`each`](https://suguru03.github.io/aigle/docs/Aigle.html#each)
- [`eachSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#eachSeries)
- [`eachLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#eachLimit)
- [`every`](https://suguru03.github.io/aigle/docs/Aigle.html#every)
- [`everySeries`](https://suguru03.github.io/aigle/docs/Aigle.html#everySeries)
- [`everyLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#everyLimit)
- [`filter`](https://suguru03.github.io/aigle/docs/Aigle.html#filter)
- [`filterSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#filterSeries)
- [`filterLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#filterLimit)
- [`find`](https://suguru03.github.io/aigle/docs/Aigle.html#find)
- [`findSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#findSeries)
- [`findLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#findLimit)
- [`findIndex`](https://suguru03.github.io/aigle/docs/Aigle.html#findIndex)
- [`findIndexSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#findIndexSeries)
- [`findIndexLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#findIndexLimit)
- [`findKey`](https://suguru03.github.io/aigle/docs/Aigle.html#findKey)
- [`findKeySeries`](https://suguru03.github.io/aigle/docs/Aigle.html#findKeySeries)
- [`findKeyLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#findKeyLimit)
- [`forEach`](https://suguru03.github.io/aigle/docs/Aigle.html#each) -> [`each`](https://suguru03.github.io/aigle/docs/Aigle.html#each)
- [`forEachSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#eachSeries) -> [`eachSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#eachSeries)
- [`forEachLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#eachLimit) -> [`eachLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#eachLimit)
- [`groupBy`](https://suguru03.github.io/aigle/docs/Aigle.html#groupBy)
- [`groupBySeries`](https://suguru03.github.io/aigle/docs/Aigle.html#groupBySeries)
- [`groupByLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#groupByLimit)
- [`map`](https://suguru03.github.io/aigle/docs/Aigle.html#map)
- [`mapSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#mapSeries)
- [`mapLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#mapLimit)
- [`mapValues`](https://suguru03.github.io/aigle/docs/Aigle.html#mapValues)
- [`mapValuesSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#mapValuesSeries)
- [`mapValuesLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#mapValuesLimit)
- [`omit`](https://suguru03.github.io/aigle/docs/Aigle.html#omit)
- [`omitSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#omitBySeries) -> [`omitBySeries`](https://suguru03.github.io/aigle/docs/Aigle.html#omitBySeries)
- [`omitLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#omitByLimit) -> [`omitByLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#omitByLimit)
- [`omitBy`](https://suguru03.github.io/aigle/docs/Aigle.html#omitBy)
- [`omitBySeries`](https://suguru03.github.io/aigle/docs/Aigle.html#omitBySeries)
- [`omitByLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#omitByLimit)
- [`pick`](https://suguru03.github.io/aigle/docs/Aigle.html#pick)
- [`pickSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#pickBySeries) -> [`pickBySeries`](https://suguru03.github.io/aigle/docs/Aigle.html#pickBySeries)
- [`pickLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#pickByLimit) -> [`pickByLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#pickByLimit)
- [`pickBy`](https://suguru03.github.io/aigle/docs/Aigle.html#pickBy)
- [`pickBySeries`](https://suguru03.github.io/aigle/docs/Aigle.html#pickBySeries)
- [`pickByLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#pickByLimit)
- [`reduce`](https://suguru03.github.io/aigle/docs/Aigle.html#reduce)
- [`reduceSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#reduceSeries)
- [`reduceLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#reduceLimit)
- [`reject`](https://suguru03.github.io/aigle/docs/Aigle.html#reject)
- [`rejectSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#rejectSeries)
- [`rejectLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#rejectLimit)
- [`some`](https://suguru03.github.io/aigle/docs/Aigle.html#some)
- [`someSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#someSeries)
- [`someLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#someLimit)
- [`sortBy`](https://suguru03.github.io/aigle/docs/Aigle.html#sortBy)
- [`sortBySeries`](https://suguru03.github.io/aigle/docs/Aigle.html#sortBySeries)
- [`sortByLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#sortByLimit)
- [`transform`](https://suguru03.github.io/aigle/docs/Aigle.html#transform)
- [`transformSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#transformSeries)
- [`transformLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#transformLimit)
#### class functions
- [`Promise.concat`](https://suguru03.github.io/aigle/docs/global.html#concat)
- [`Promise.concatSeries`](https://suguru03.github.io/aigle/docs/global.html#concatSeries)
- [`Promise.concatLimit`](https://suguru03.github.io/aigle/docs/global.html#concatLimit)
- [`Promise.each`](https://suguru03.github.io/aigle/docs/global.html#each)
- [`Promise.eachSeries`](https://suguru03.github.io/aigle/docs/global.html#eachSeries)
- [`Promise.eachLimit`](https://suguru03.github.io/aigle/docs/global.html#eachLimit)
- [`Promise.every`](https://suguru03.github.io/aigle/docs/global.html#every)
- [`Promise.everySeries`](https://suguru03.github.io/aigle/docs/global.html#everySeries)
- [`Promise.everyLimit`](https://suguru03.github.io/aigle/docs/global.html#everyLimit)
- [`Promise.filter`](https://suguru03.github.io/aigle/docs/global.html#filter)
- [`Promise.filterSeries`](https://suguru03.github.io/aigle/docs/global.html#filterSeries)
- [`Promise.filterLimit`](https://suguru03.github.io/aigle/docs/global.html#filterLimit)
- [`Promise.find`](https://suguru03.github.io/aigle/docs/global.html#find)
- [`Promise.findSeries`](https://suguru03.github.io/aigle/docs/global.html#findSeries)
- [`Promise.findLimit`](https://suguru03.github.io/aigle/docs/global.html#findLimit)
- [`Promise.findIndex`](https://suguru03.github.io/aigle/docs/global.html#findIndex)
- [`Promise.findIndexSeries`](https://suguru03.github.io/aigle/docs/global.html#findIndexSeries)
- [`Promise.findIndexLimit`](https://suguru03.github.io/aigle/docs/global.html#findIndexLimit)
- [`Promise.findKey`](https://suguru03.github.io/aigle/docs/global.html#findKey)
- [`Promise.findKeySeries`](https://suguru03.github.io/aigle/docs/global.html#findKeySeries)
- [`Promise.findKeyLimit`](https://suguru03.github.io/aigle/docs/global.html#findKeyLimit)
- [`Promise.forEach`](https://suguru03.github.io/aigle/docs/global.html#each) -> [`Promise.each`](https://suguru03.github.io/aigle/docs/global.html#each)
- [`Promise.forEachSeries`](https://suguru03.github.io/aigle/docs/global.html#eachSeries) -> [`Promise.eachSeries`](https://suguru03.github.io/aigle/docs/global.html#eachSeries)
- [`Promise.forEachLimit`](https://suguru03.github.io/aigle/docs/global.html#eachLimit) -> [`Promise.eachLimit`](https://suguru03.github.io/aigle/docs/global.html#eachLimit)
- [`Promise.groupBy`](https://suguru03.github.io/aigle/docs/global.html#groupBy)
- [`Promise.groupBySeries`](https://suguru03.github.io/aigle/docs/global.html#groupBySeries)
- [`Promise.groupByLimit`](https://suguru03.github.io/aigle/docs/global.html#groupByLimit)
- [`Promise.map`](https://suguru03.github.io/aigle/docs/global.html#map)
- [`Promise.mapSeries`](https://suguru03.github.io/aigle/docs/global.html#mapSeries)
- [`Promise.mapLimit`](https://suguru03.github.io/aigle/docs/global.html#mapLimit)
- [`Promise.mapValues`](https://suguru03.github.io/aigle/docs/global.html#mapValues)
- [`Promise.mapValuesSeries`](https://suguru03.github.io/aigle/docs/global.html#mapValuesSeries)
- [`Promise.mapValuesLimit`](https://suguru03.github.io/aigle/docs/global.html#mapValuesLimit)
- [`Promise.omit`](https://suguru03.github.io/aigle/docs/global.html#omit)
- [`Promise.omitSeries`](https://suguru03.github.io/aigle/docs/global.html#omitBySeries) -> [`Promise.omitBySeries`](https://suguru03.github.io/aigle/docs/global.html#omitBySeries)
- [`Promise.omitLimit`](https://suguru03.github.io/aigle/docs/global.html#omitByLimit) -> [`Promise.omitByLimit`](https://suguru03.github.io/aigle/docs/global.html#omitByLimit)
- [`Promise.omitBy`](https://suguru03.github.io/aigle/docs/global.html#omitBy)
- [`Promise.omitBySeries`](https://suguru03.github.io/aigle/docs/global.html#omitBySeries)
- [`Promise.omitByLimit`](https://suguru03.github.io/aigle/docs/global.html#omitByLimit)
- [`Promise.pick`](https://suguru03.github.io/aigle/docs/global.html#pick)
- [`Promise.pickSeries`](https://suguru03.github.io/aigle/docs/global.html#pickBySeries) -> [`Promise.pickBySeries`](https://suguru03.github.io/aigle/docs/global.html#pickBySeries)
- [`Promise.pickLimit`](https://suguru03.github.io/aigle/docs/global.html#pickByLimit) -> [`Promise.pickByLimit`](https://suguru03.github.io/aigle/docs/global.html#pickByLimit)
- [`Promise.pickBy`](https://suguru03.github.io/aigle/docs/global.html#pickBy)
- [`Promise.pickBySeries`](https://suguru03.github.io/aigle/docs/global.html#pickBySeries)
- [`Promise.pickByLimit`](https://suguru03.github.io/aigle/docs/global.html#pickByLimit)
- [`Promise.reduce`](https://suguru03.github.io/aigle/docs/global.html#reduce)
- [`Promise.reduceSeries`](https://suguru03.github.io/aigle/docs/global.html#reduceSeries)
- [`Promise.reduceLimit`](https://suguru03.github.io/aigle/docs/global.html#reduceLimit)
- [`Promise.reject`](https://suguru03.github.io/aigle/docs/global.html#reject)
- [`Promise.rejectSeries`](https://suguru03.github.io/aigle/docs/global.html#rejectSeries)
- [`Promise.rejectLimit`](https://suguru03.github.io/aigle/docs/global.html#rejectLimit)
- [`Promise.some`](https://suguru03.github.io/aigle/docs/global.html#some)
- [`Promise.someSeries`](https://suguru03.github.io/aigle/docs/global.html#someSeries)
- [`Promise.someLimit`](https://suguru03.github.io/aigle/docs/global.html#someLimit)
- [`Promise.sortBy`](https://suguru03.github.io/aigle/docs/global.html#sortBy)
- [`Promise.sortBySeries`](https://suguru03.github.io/aigle/docs/global.html#sortBySeries)
- [`Promise.sortByLimit`](https://suguru03.github.io/aigle/docs/global.html#sortByLimit)
- [`Promise.transform`](https://suguru03.github.io/aigle/docs/global.html#transform)
- [`Promise.transformSeries`](https://suguru03.github.io/aigle/docs/global.html#transformSeries)
- [`Promise.transformLimit`](https://suguru03.github.io/aigle/docs/global.html#transformLimit)
### Control flow
#### prototype functions
- [`all`](https://suguru03.github.io/aigle/docs/Aigle.html#all)
- [`doUntil`](https://suguru03.github.io/aigle/docs/Aigle.html#doUntil)
- [`doWhilst`](https://suguru03.github.io/aigle/docs/Aigle.html#doWhilst)
- [`parallel`](https://suguru03.github.io/aigle/docs/Aigle.html#parallel)
- [`props`](https://suguru03.github.io/aigle/docs/Aigle.html#props)
- [`race`](https://suguru03.github.io/aigle/docs/Aigle.html#race)
- [`times`](https://suguru03.github.io/aigle/docs/Aigle.html#times)
- [`timesSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#timesSeries)
- [`timesLimit`](https://suguru03.github.io/aigle/docs/Aigle.html#timesLimit)
- [`until`](https://suguru03.github.io/aigle/docs/Aigle.html#until)
- [`whilst`](https://suguru03.github.io/aigle/docs/Aigle.html#whilst)
#### class functions
- [`Promise.all`](https://suguru03.github.io/aigle/docs/global.html#all)
- [`Promise.doUntil`](https://suguru03.github.io/aigle/docs/global.html#doUntil)
- [`Promise.doWhilst`](https://suguru03.github.io/aigle/docs/global.html#doWhilst)
- [`Promise.parallel`](https://suguru03.github.io/aigle/docs/global.html#parallel)
- [`Promise.props`](https://suguru03.github.io/aigle/docs/global.html#props)
- [`Promise.race`](https://suguru03.github.io/aigle/docs/global.html#race)
- [`Promise.retry`](https://suguru03.github.io/aigle/docs/global.html#retry)
- [`Promise.times`](https://suguru03.github.io/aigle/docs/global.html#times)
- [`Promise.timesSeries`](https://suguru03.github.io/aigle/docs/global.html#timesSeries)
- [`Promise.timesLimit`](https://suguru03.github.io/aigle/docs/global.html#timesLimit)
- [`Promise.until`](https://suguru03.github.io/aigle/docs/global.html#until)
- [`Promise.whilst`](https://suguru03.github.io/aigle/docs/global.html#whilst)
### Utils
#### prototype functions
- [`delay`](https://suguru03.github.io/aigle/docs/Aigle.html#delay)
- [`promisify`](https://suguru03.github.io/aigle/docs/Aigle.html#promisify)
- [`promisifyAll`](https://suguru03.github.io/aigle/docs/Aigle.html#promisifyAll)
- [`timeout`](https://suguru03.github.io/aigle/docs/Aigle.html#timeout)
#### class functions
- [`Promise.delay`](https://suguru03.github.io/aigle/docs/global.html#delay)
- [`Promise.mixin`](https://suguru03.github.io/aigle/docs/global.html#mixin)
- [`Promise.promisify`](https://suguru03.github.io/aigle/docs/global.html#promisify)
- [`Promise.promisifyAll`](https://suguru03.github.io/aigle/docs/global.html#promisifyAll)
- [`Promise.config`](https://suguru03.github.io/aigle/docs/global.html#config)
### Debug
#### class functions
- [`Promise.longStackTraces`](https://suguru03.github.io/aigle/docs/global.html#longStackTrases)
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1 @@
{"main":"../lib/aigle","browser":"../aigle-es5.min.js"}
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').all;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').allSettled;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').attempt;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').concat;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').concatLimit;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').concatSeries;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').config;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').default;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').delay;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').detect;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').detectLimit;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').detectSeries;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').doUntil;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').doWhilst;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').each;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').eachLimit;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').eachSeries;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').every;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').everyLimit;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').everySeries;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').filter;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').filterLimit;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').filterSeries;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').find;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').findIndex;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').findIndexLimit;
@@ -0,0 +1 @@
module.exports = require('./aigle').findIndexSeries;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').findKey;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').findKeyLimit;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').findKeySeries;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').findLimit;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').findSeries;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').flow;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').forEach;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').forEachLimit;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').forEachSeries;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').groupBy;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').groupByLimit;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').groupBySeries;
+1
View File
@@ -0,0 +1 @@
module.exports = require('./aigle').join;
File diff suppressed because it is too large Load Diff
+89
View File
@@ -0,0 +1,89 @@
'use strict';
const { AigleProxy } = require('aigle-core');
const Aigle = require('./aigle');
const {
INTERNAL,
PENDING,
iteratorSymbol,
promiseArrayEach,
promiseSetEach
} = require('./internal/util');
const { callResolve } = require('./props');
class All extends AigleProxy {
constructor(coll) {
super();
this._promise = new Aigle(INTERNAL);
this._rest = undefined;
this._result = undefined;
if (coll === PENDING) {
this._callResolve = this._set;
} else {
this._callResolve = undefined;
this._set(coll);
}
}
_set(coll) {
if (Array.isArray(coll)) {
const size = coll.length;
this._rest = size;
this._result = Array(size);
this._callResolve = callResolve;
promiseArrayEach(this, size, coll);
} else if (coll[iteratorSymbol]) {
const { size } = coll;
this._rest = size;
this._result = Array(size);
this._callResolve = callResolve;
promiseSetEach(this, Infinity, coll);
} else {
this._rest = 0;
this._result = [];
}
if (this._rest === 0) {
this._promise._resolve(this._result);
}
return this;
}
_execute() {
return this._promise;
}
_callReject(reason) {
this._promise._reject(reason);
}
}
module.exports = { all, All };
/**
* `Aigle.all` is almost the same functionality as `Promise.all`.
* It will return an Aigle instance.
* @param {Array} array
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const makeDelay = (num, delay) => {
* return Aigle.delay(delay)
* .then(() => {
* order.push(num);
* return num;
* });
* };
* Aigle.all([
* makeDelay(1, 30),
* makeDelay(2, 20),
* makeDelay(3, 10)
* ])
* .then(array => {
* console.log(array); // [1, 2, 3];
* console.log(order); // [3, 2, 1];
* });
*/
function all(array) {
return new All(array)._promise;
}
+58
View File
@@ -0,0 +1,58 @@
'use strict';
const { Parallel } = require('./parallel');
class AllSettled extends Parallel {
_set(coll) {
this._errorSet = new Set();
this._promise._resolve = createResolve(this);
super._set(coll);
}
_callReject(reason, key) {
this._errorSet.add(key);
this._callResolve(reason, key);
return true;
}
}
function createResolve(proxy) {
const { _errorSet, _promise } = proxy;
const { _resolve } = _promise;
return result => {
if (Array.isArray(result)) {
result = result.map(iterator);
} else if (result instanceof Map) {
const map = result;
result = map;
map.forEach((val, key) => result.set(key, iterator(val, key)));
} else {
Object.entries(result).forEach(([key, val]) => (result[key] = iterator(val, key)));
}
_resolve.call(_promise, result);
};
function iterator(res, key) {
return _errorSet.has(key)
? { state: 'rejected', reason: res }
: { state: 'fulfilled', value: res };
}
}
module.exports = { allSettled, AllSettled };
/**
* Return an Aigle instance
* @param {Array|Object} collection - it should be an array/object of functions or Promise instances
* @example
* Aigle.allSettled([
* Aigle.resolve(1),
* Aigle.reject(2),
* Aigle.reject(3)
* ])
* .then(array => {
* console.log(array); // [{ state: 'fulfilled', value: 1 }, { state: 'rejected', reason: 2 }, { state: 'rejected', reason: 3 }]
* });
*/
function allSettled(collection) {
return new AllSettled(collection)._promise;
}
+21
View File
@@ -0,0 +1,21 @@
'use strict';
const Aigle = require('./aigle');
const { INTERNAL, callResolve } = require('./internal/util');
module.exports = attempt;
/**
* @param {function} handler
* @return {Aigle} Returns an Aigle instance
* @example
* Aigle.attempt(() => {
* throw Error('error');
* })
* .catch(error => console.log(error)); // error
*/
function attempt(handler) {
const receiver = new Aigle(INTERNAL);
callResolve(receiver, handler);
return receiver;
}
+72
View File
@@ -0,0 +1,72 @@
'use strict';
const { Each } = require('./each');
const { concatArray } = require('./internal/util');
const { setParallel } = require('./internal/collection');
class Concat extends Each {
constructor(collection, iterator) {
super(collection, iterator, set);
}
_callResolve(value, index) {
this._result[index] = value;
if (--this._rest === 0) {
this._promise._resolve(concatArray(this._result));
}
}
}
module.exports = { concat, Concat };
function set(collection) {
setParallel.call(this, collection);
this._result = Array(this._rest);
return this;
}
/**
* `Aigle.concat` has almost the same functionality as `Array#concat`.
* It iterates all elements of `collection` and executes `iterator` using each element on parallel.
* The `iterator` needs to return a promise or something.
* If a promise is returned, the function will wait until the promise is fulfilled.
* Then the result will be assigned to an array, the role is the same as `Array#concat`.
* All of them are finished, the function will return an array as a result.
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = (num, index, collection) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num;
* });
* };
* Aigle.concat(collection, iterator)
* .then(array => {
* console.log(array); // [1, 2, 4];
* console.log(order); // [1, 2, 4];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = (num, key, collection) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num;
* });
* };
* Aigle.concat(collection, iterator)
* .then(array => {
* console.log(array); // [1, 2, 4];
* console.log(order); // [1, 2, 4];
* });
*/
function concat(collection, iterator) {
return new Concat(collection, iterator)._execute();
}
+93
View File
@@ -0,0 +1,93 @@
'use strict';
const { EachLimit } = require('./eachLimit');
const { concatArray } = require('./internal/util');
const { setLimit } = require('./internal/collection');
class ConcatLimit extends EachLimit {
constructor(collection, limit, iterator) {
super(collection, limit, iterator, set);
}
_callResolve(value, index) {
this._result[index] = value;
if (--this._rest === 0) {
this._promise._resolve(concatArray(this._result));
} else if (this._callRest-- > 0) {
this._iterate();
}
}
}
module.exports = { concatLimit, ConcatLimit };
function set(collection) {
setLimit.call(this, collection);
this._result = Array(this._rest);
return this;
}
/**
* `Aigle.concatLimit` is almost the as [`Aigle.concat`](https://suguru03.github.io/aigle/docs/Aigle.html#concat) and
* [`Aigle.concatSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#concatSeries), but it will work with concurrency.
* @param {Array|Object} collection
* @param {integer} [limit=8]
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = (num, index, collection) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num;
* });
* };
* Aigle.concatLimit(collection, 2, iterator)
* .then(array => {
* console.log(array); // [1, 3, 5, 2, 4];
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = {
* task1: 1,
* task2: 5,
* task3: 3,
* task4: 4,
* task5: 2
* };
* const iterator = (num, key, collection) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num;
* });
* };
* Aigle.concatLimit(collection, 2, iterator)
* .then(array => {
* console.log(array); // [1, 3, 5, 2, 4];
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num;
* });
* };
* Aigle.concatLimit(collection, iterator)
* .then(array => {
* console.log(array); // [1, 2, 3, 4, 5];
* console.log(order); // [1, 2, 3, 4, 5];
* });
*/
function concatLimit(collection, limit, iterator) {
return new ConcatLimit(collection, limit, iterator)._execute();
}
+66
View File
@@ -0,0 +1,66 @@
'use strict';
const { EachSeries } = require('./eachSeries');
class ConcatSeries extends EachSeries {
constructor(collection, iterator) {
super(collection, iterator);
this._result = [];
}
_callResolve(value) {
if (Array.isArray(value)) {
this._result.push(...value);
} else if (value !== undefined) {
this._result.push(value);
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
}
module.exports = { concatSeries, ConcatSeries };
/**
* `Aigle.concatSeries` is almost the as [`Aigle.concat`](https://suguru03.github.io/aigle/docs/Aigle.html#concat), but it will work in series.
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = (num, index, collection) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num;
* });
* };
* Aigle.concatSeries(collection, iterator)
* .then(array => {
* console.log(array); // [1, 4, 2];
* console.log(order); // [1, 4, 2];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = (num, key, collection) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num;
* });
* };
* Aigle.concatSeries(collection, iterator)
* .then(array => {
* console.log(array); // [1, 4, 2];
* console.log(order); // [1, 4, 2];
* });
*/
function concatSeries(collection, iterator) {
return new ConcatSeries(collection, iterator)._execute();
}
+37
View File
@@ -0,0 +1,37 @@
'use strict';
module.exports = {
resolveStack,
reconstructStack
};
function resolveStack(promise) {
Error.captureStackTrace(promise);
}
function reconstructStack(promise) {
const { stack, _value } = promise;
if (_value instanceof Error === false || !stack) {
return;
}
if (!_value._reconstruct) {
_value.stack = reconstruct(_value.stack).join('\n');
_value._reconstruct = true;
}
const stacks = reconstruct(stack);
stacks[0] = '\nFrom previous event:';
_value.stack += stacks.join('\n');
}
function reconstruct(stack) {
const result = [];
const stacks = stack.split('\n');
for (let i = 0; i < stacks.length; i++) {
const s = stacks[i];
if (/node_modules/.test(s)) {
continue;
}
result.push(s);
}
return result;
}
+41
View File
@@ -0,0 +1,41 @@
'use strict';
const Aigle = require('./aigle');
const { INTERNAL } = require('./internal/util');
class Delay extends Aigle {
constructor(ms) {
super(INTERNAL);
this._ms = ms;
this._timer = undefined;
}
_resolve(value) {
this._timer = setTimeout(() => Aigle.prototype._resolve.call(this, value), this._ms);
return this;
}
_reject(reason) {
clearTimeout(this._timer);
Aigle.prototype._reject.call(this, reason);
}
}
module.exports = { delay, Delay };
/**
* Return a promise which will be resolved with `value` after `ms`.
* @param {number} ms
* @param {*} value
* @return {Aigle} Returns an Aigle instance
* @example
* Aigle.delay(10)
* .then(value => console.log(value); // undefined
*
* @example
* Aigle.delay(10, 'test')
* .then(value => console.log(value); // 'test'
*/
function delay(ms, value) {
return new Delay(ms)._resolve(value);
}
+60
View File
@@ -0,0 +1,60 @@
'use strict';
const { DoWhilst } = require('./doWhilst');
const { UntilTester } = require('./until');
module.exports = doUntil;
/**
* @param {*} [value]
* @param {Function} iterator
* @param {Function} tester
* @return {Aigle} Returns an Aigle instance
* @example
* let count = 0;
* const order = [];
* const tester = num => {
* order.push(`t:${num}`);
* return Aigle.delay(10)
* .then(() => num === 4);
* };
* const iterator = () => {
* const num = ++count;
* order.push(`i:${num}`);
* return Aigle.delay(10)
* .then(() => num);
* };
* Aigle.doUntil(iterator, tester)
* .then(value => {
* console.log(value); // 4
* console.log(count); // 4
* console.log(order); // [ 'i:1', 't:1', 'i:2', 't:2', 'i:3', 't:3', 'i:4', 't:4' ]
* });
*
* @example
* const order = [];
* const tester = num => {
* order.push(`t:${num}`);
* return Aigle.delay(10)
* .then(() => num === 4);
* };
* const iterator = count => {
* const num = ++count;
* order.push(`i:${num}`);
* return Aigle.delay(10)
* .then(() => num);
* };
* Aigle.doUntil(0, iterator, tester)
* .then(value => {
* console.log(value); // 4
* console.log(order); // [ 'i:1', 't:1', 'i:2', 't:2', 'i:3', 't:3', 'i:4', 't:4' ]
* });
*/
function doUntil(value, iterator, tester) {
if (typeof tester !== 'function') {
tester = iterator;
iterator = value;
value = undefined;
}
return new DoWhilst(new UntilTester(tester), iterator)._iterate(value);
}
+70
View File
@@ -0,0 +1,70 @@
'use strict';
const { AigleWhilst, WhilstTester } = require('./whilst');
class DoWhilst extends AigleWhilst {
constructor(test, iterator) {
super(test, iterator);
}
_iterate(value) {
this._next(value);
return this._promise;
}
}
module.exports = { doWhilst, DoWhilst };
/**
* @param {*} [value]
* @param {Function} iterator
* @param {Function} tester
* @return {Aigle} Returns an Aigle instance
* @example
* let count = 0;
* const order = [];
* const tester = num => {
* order.push(`t:${num}`);
* return Aigle.delay(10)
* .then(() => num !== 4);
* };
* const iterator = () => {
* const num = ++count;
* order.push(`i:${num}`);
* return Aigle.delay(10)
* .then(() => num);
* };
* Aigle.doWhilst(iterator, tester)
* .then(value => {
* console.log(value); // 4
* console.log(count); // 4
* console.log(order); // [ 'i:1', 't:1', 'i:2', 't:2', 'i:3', 't:3', 'i:4', 't:4' ]
* });
*
* @example
* const order = [];
* const tester = num => {
* order.push(`t:${num}`);
* return Aigle.delay(10)
* .then(() => num !== 4);
* };
* const iterator = count => {
* const num = ++count;
* order.push(`i:${num}`);
* return Aigle.delay(10)
* .then(() => num);
* };
* Aigle.doWhilst(0, iterator, tester)
* .then(value => {
* console.log(value); // 4
* console.log(order); // [ 'i:1', 't:1', 'i:2', 't:2', 'i:3', 't:3', 'i:4', 't:4' ]
* });
*/
function doWhilst(value, iterator, tester) {
if (typeof tester !== 'function') {
tester = iterator;
iterator = value;
value = undefined;
}
return new DoWhilst(new WhilstTester(tester), iterator)._iterate(value);
}
+109
View File
@@ -0,0 +1,109 @@
'use strict';
const { AigleProxy } = require('aigle-core');
const Aigle = require('./aigle');
const { INTERNAL, PENDING } = require('./internal/util');
const { execute, setParallel } = require('./internal/collection');
class Each extends AigleProxy {
constructor(collection, iterator, set = setDefault) {
super();
this._iterator = iterator;
this._promise = new Aigle(INTERNAL);
this._coll = undefined;
this._size = undefined;
this._rest = undefined;
this._keys = undefined;
this._result = undefined;
this._iterate = undefined;
if (collection === PENDING) {
this._set = set;
this._iterate = this._callResolve;
this._callResolve = execute;
} else {
set.call(this, collection);
}
}
_execute() {
if (this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
return this._promise;
}
_callResolve(value) {
if (--this._rest === 0 || value === false) {
this._promise._resolve(this._result);
}
}
_callReject(reason) {
this._promise._reject(reason);
}
}
module.exports = { each, Each };
function setDefault(collection) {
setParallel.call(this, collection);
this._result = collection;
return this;
}
/**
* `Aigle.each` iterates all elements of `collection` and execute `iterator` for each element on parallel.
* The iterator is called with three arguments. (value, index|key, collection)
* If the iterator returns `false` or a promise which has `false` as a result, the promise state will be `onFulfilled` immediately.
* ⚠ All elements are already executed and can't be stopped. If you care about it, you should use [`Aigle.eachSeries`](https://suguru03.github.io/aigle/docs/global.html#eachSeries).
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = (num, index, collection) => {
* return Aigle.delay(num * 10)
* .then(() => order.push(num));
* };
* return Aigle.each(collection, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 2, 4];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = (num, key, collection) => {
* return Aigle.delay(num * 10)
* .then(() => order.push(num));
* };
* return Aigle.each(collection, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 2, 4];
* });
*
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = (num, index, collection) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num !== 2; // break
* });
* };
* return Aigle.each(collection, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 2];
* });
*/
function each(collection, iterator) {
return new Each(collection, iterator)._execute();
}
+153
View File
@@ -0,0 +1,153 @@
'use strict';
const { AigleProxy } = require('aigle-core');
const Aigle = require('./aigle');
const { DEFAULT_LIMIT, INTERNAL, PENDING } = require('./internal/util');
const { execute, setLimit } = require('./internal/collection');
class EachLimit extends AigleProxy {
constructor(collection, limit, iterator, set = setDefault) {
super();
if (typeof limit === 'function') {
iterator = limit;
limit = DEFAULT_LIMIT;
}
this._iterator = iterator;
this._promise = new Aigle(INTERNAL);
this._index = 0;
this._limit = limit;
this._coll = undefined;
this._rest = undefined;
this._size = undefined;
this._keys = undefined;
this._result = undefined;
this._iterate = undefined;
this._callRest = undefined;
if (collection === PENDING) {
this._set = set;
this._iterate = this._callResolve;
this._callResolve = execute;
} else {
set.call(this, collection);
}
}
_execute() {
if (this._rest === 0) {
this._promise._resolve(this._result);
} else {
while (this._limit--) {
this._iterate();
}
}
return this._promise;
}
_callResolve(value) {
if (value === false) {
this._callRest = 0;
this._promise._resolve(this._result);
} else if (--this._rest === 0) {
this._promise._resolve(this._result);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
_callReject(reason) {
this._callRest = 0;
this._promise._reject(reason);
}
}
module.exports = { eachLimit, EachLimit };
function setDefault(collection) {
setLimit.call(this, collection);
this._result = collection;
return this;
}
/**
* `Aigle.eachLimit` is almost same as [`Aigle.each`](https://suguru03.github.io/aigle/docs/Aigle.html#each)
* and [`Aigle.eachSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#eachSeries),
* but it will work with concurrency.
* `limit` is concurrency, if it is not defined, concurrency is 8.
* @param {Array|Object} A - collection to iterate over
* @param {integer} [limit=8] - It is concurrncy, default is 8
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num;
* });
* };
* Aigle.eachLimit(collection, 2, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = {
* task1: 1,
* task2: 5,
* task3: 3,
* task4: 4,
* task5: 2
* };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num;
* });
* };
* Aigle.eachLimit(collection, 2, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num;
* });
* };
* Aigle.eachLimit(collection, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 2, 3, 4, 5];
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num !== 3;
* });
* };
* Aigle.eachLimit(collection, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 2, 3];
* });
*/
function eachLimit(collection, limit, iterator) {
return new EachLimit(collection, limit, iterator)._execute();
}
+109
View File
@@ -0,0 +1,109 @@
'use strict';
const { AigleProxy } = require('aigle-core');
const Aigle = require('./aigle');
const { INTERNAL, PENDING } = require('./internal/util');
const { execute, setSeries } = require('./internal/collection');
class EachSeries extends AigleProxy {
constructor(collection, iterator, set = setDefault) {
super();
this._iterator = iterator;
this._promise = new Aigle(INTERNAL);
this._index = 0;
this._coll = undefined;
this._rest = undefined;
this._size = undefined;
this._keys = undefined;
this._result = undefined;
this._iterate = undefined;
if (collection === PENDING) {
this._set = set;
this._iterate = this._callResolve;
this._callResolve = execute;
} else {
set.call(this, collection);
}
}
_execute() {
if (this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
return this._promise;
}
_callResolve(value) {
if (--this._rest === 0 || value === false) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
_callReject(reason) {
this._promise._reject(reason);
}
}
module.exports = { eachSeries, EachSeries };
function setDefault(collection) {
setSeries.call(this, collection);
this._result = collection;
return this;
}
/**
* `Aigle.eachSeries` is almost the same as [`Aigle.each`](https://suguru03.github.io/aigle/docs/Aigle.html#each), but it will work in series.
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => order.push(num));
* };
* Aigle.eachSeries(collection, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 4, 2];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => order.push(num));
* };
* Aigle.eachSeries(collection, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 4, 2];
* });
*
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num !== 4; // break
* });
* };
* Aigle.eachSeries(collection, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 4];
* });
*/
function eachSeries(collection, iterator) {
return new EachSeries(collection, iterator)._execute();
}
+10
View File
@@ -0,0 +1,10 @@
'use strict';
const types = ['CancellationError', 'TimeoutError'];
let l = types.length;
while (l--) {
const name = types[l];
const Class = class extends Error {};
Class.prototype.name = name;
exports[name] = Class;
}
+119
View File
@@ -0,0 +1,119 @@
'use strict';
const { Each } = require('./each');
const { PENDING } = require('./internal/util');
const { setShorthand } = require('./internal/collection');
class Every extends Each {
constructor(collection, iterator) {
super(collection, iterator);
this._result = true;
if (collection === PENDING) {
this._set = setShorthand;
} else {
setShorthand.call(this, collection);
}
}
_callResolve(value) {
if (!value) {
this._promise._resolve(false);
} else if (--this._rest === 0) {
this._promise._resolve(true);
}
}
}
module.exports = { every, Every };
/**
* `Aigle.every` is similar to `Array#every`.
* If all elements return truthly or a promise which has a truthly value as a result,
* the result will be `true`, otherwise it will be `false`.
* @param {Array|Object} collection
* @param {Function|Array|Object|string} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = (num, index, collection) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return true;
* });
* };
* Aigle.every(collection, iterator)
* .then(value => {
* console.log(value); // true
* console.log(order); // [1, 2, 4];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = (num, key, collection) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return true;
* });
* };
* Aigle.every(collection, iterator)
* .then(value => {
* console.log(value); // true
* console.log(order); // [1, 2, 4];
* });
*
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return n % 2;
* });
* };
* Aigle.every(collection, iterator)
* .then(value => {
* console.log(value); // false
* console.log(order); // [1, 2];
* });
*
* @example
* const collection = [{
* uid: 1, active: false
* }, {
* uid: 4, active: true
* }, {
* uid: 2, active: true
* }];
* Aigle.every(collection, 'active')
* .then(value => console.log(value)); // false
*
* @example
* const collection = [{
* uid: 1, active: false
* }, {
* uid: 4, active: true
* }, {
* uid: 2, active: true
* }];
* Aigle.every(collection, ['active', true])
* .then(value => console.log(value)); // false
*
* @example
* const collection = [{
* uid: 1, active: true
* }, {
* uid: 4, active: true
* }, {
* uid: 2, active: true
* }];
* Aigle.every(collection, { active: true })
* .then(value => console.log(value)); // true
*/
function every(collection, iterator) {
return new Every(collection, iterator)._execute();
}
+85
View File
@@ -0,0 +1,85 @@
'use strict';
const { EachLimit } = require('./eachLimit');
class EveryLimit extends EachLimit {
constructor(collection, limit, iterator) {
super(collection, limit, iterator);
this._result = true;
}
_callResolve(value) {
if (!value) {
this._promise._resolve(false);
} else if (--this._rest === 0) {
this._promise._resolve(true);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
}
module.exports = { everyLimit, EveryLimit };
/**
* @param {Array|Object} collection
* @param {integer} [limit=8]
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return true;
* });
* };
* Aigle.everyLimit(collection, 2, iterator)
* .then(value => {
* console.log(value); // true
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = {
* task1: 1,
* task2: 5,
* task3: 3,
* task4: 4,
* task5: 2
* };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return true;
* });
* };
* Aigle.everyLimit(collection, 2, iterator)
* .then(value => {
* console.log(value); // true
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num === 4;
* });
* };
* Aigle.everyLimit(collection, iterator)
* .then(value => {
* console.log(value); // false
* console.log(order); // [1, 2, 3, 4];
* });
*/
function everyLimit(collection, limit, iterator) {
return new EveryLimit(collection, limit, iterator)._execute();
}
+79
View File
@@ -0,0 +1,79 @@
'use strict';
const { EachSeries } = require('./eachSeries.js');
class EverySeries extends EachSeries {
constructor(collection, iterator) {
super(collection, iterator);
this._result = true;
}
_callResolve(value) {
if (!value) {
this._promise._resolve(false);
} else if (--this._rest === 0) {
this._promise._resolve(true);
} else {
this._iterate();
}
}
}
module.exports = { everySeries, EverySeries };
/**
* `Aigle.everySeries` is almost the same as [`Aigle.every`](https://suguru03.github.io/aigle/docs/Aigle.html#every), but it will work in series.
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = (num, index, collection) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return true;
* });
* };
* Aigle.everySeries(collection, iterator)
* .then(value => {
* console.log(value); // true
* console.log(order); // [1, 4, 2];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = (num, key, collection) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return true;
* });
* };
* Aigle.everySeries(collection, iterator)
* .then(value => {
* console.log(value); // true
* console.log(order); // [1, 4, 2];
* });
*
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return n % 2;
* });
* };
* Aigle.everySeries(collection, iterator)
* .then(value => {
* console.log(value); // false
* console.log(order); // [1, 4];
* });
*/
function everySeries(collection, iterator) {
return new EverySeries(collection, iterator)._execute();
}
+118
View File
@@ -0,0 +1,118 @@
'use strict';
const { Each } = require('./each');
const { setShorthand } = require('./internal/collection');
const { INTERNAL, compactArray } = require('./internal/util');
class Filter extends Each {
constructor(collection, iterator) {
super(collection, iterator, set);
}
}
Filter.prototype._set = set;
module.exports = { filter, Filter };
function set(collection) {
setShorthand.call(this, collection);
this._result = Array(this._rest);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
this._result[index] = value ? this._coll[index] : INTERNAL;
if (--this._rest === 0) {
this._promise._resolve(compactArray(this._result));
}
}
function callResolveObject(value, index) {
this._result[index] = value ? this._coll[this._keys[index]] : INTERNAL;
if (--this._rest === 0) {
this._promise._resolve(compactArray(this._result));
}
}
/**
* `Aigle.filter` has almost the same functionality as `Array#filter`.
* It iterates all elements of `collection` and executes `iterator` using each element on parallel.
* The `iterator` needs to return a promise or something.
* If a promise is returned, the function will wait until the promise is fulfilled.
* If the result is falsy, the element will be removed.
* All of them are finished, the function will return an array as a result.
* @param {Array|Object} collection
* @param {Function|Array|Object|string} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.filter(collection, iterator)
* .then(array => {
* console.log(array); // [1];
* console.log(order); // [1, 2, 4];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.filter(collection, iterator)
* .then(array => {
* console.log(array); // [1];
* console.log(order); // [1, 2, 4];
* });
*
* @example
* const order = [];
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.filter(collection, 'active')
* .then(array => {
* console.log(array); // [{ name: 'fread', active: true }]
* });
*
* @example
* const order = [];
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.filter(collection, ['name', 'fread'])
* .then(array => {
* console.log(array); // [{ name: 'fread', active: true }]
* });
*
* @example
* const order = [];
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.filter(collection, { name: 'fread', active: true })
* .then(array => {
* console.log(array); // [{ name: 'fread', active: true }]
* });
*/
function filter(collection, iterator) {
return new Filter(collection, iterator)._execute();
}
+103
View File
@@ -0,0 +1,103 @@
'use strict';
const { EachLimit } = require('./eachLimit');
const { setLimit } = require('./internal/collection');
const { INTERNAL, compactArray } = require('./internal/util');
class FilterLimit extends EachLimit {
constructor(collection, limit, iterator) {
super(collection, limit, iterator, set);
}
}
module.exports = { filterLimit, FilterLimit };
function set(collection) {
setLimit.call(this, collection);
this._result = Array(this._rest);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
this._result[index] = value ? this._coll[index] : INTERNAL;
if (--this._rest === 0) {
this._promise._resolve(compactArray(this._result));
} else if (this._callRest-- > 0) {
this._iterate();
}
}
function callResolveObject(value, index) {
this._result[index] = value ? this._coll[this._keys[index]] : INTERNAL;
if (--this._rest === 0) {
this._promise._resolve(compactArray(this._result));
} else if (this._callRest-- > 0) {
this._iterate();
}
}
/**
* `Aigle.filterLimit` is almost the as [`Aigle.filter`](https://suguru03.github.io/aigle/docs/Aigle.html#filter) and
* [`Aigle.filterSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#filterSeries), but it will work with concurrency.
* @param {Array|Object} collection
* @param {integer} [limit=8]
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.filterLimit(collection, 2, iterator)
* .then(array => {
* console.log(array); // [1, 5, 3];
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = {
* task1: 1,
* task2: 5,
* task3: 3,
* task4: 4,
* task5: 2
* };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.filterLimit(collection, 2, iterator)
* .then(array => {
* console.log(array); // [1, 5, 3];
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.filterLimit(collection, iterator)
* .then(array => {
* console.log(array); // [1, 5, 3];
* console.log(order); // [1, 2, 3, 4, 5];
* });
*/
function filterLimit(collection, limit, iterator) {
return new FilterLimit(collection, limit, iterator)._execute();
}
+79
View File
@@ -0,0 +1,79 @@
'use strict';
const { EachSeries } = require('./eachSeries');
const { setSeries } = require('./internal/collection');
const { INTERNAL, compactArray } = require('./internal/util');
class FilterSeries extends EachSeries {
constructor(collection, iterator) {
super(collection, iterator, set);
}
}
module.exports = { filterSeries, FilterSeries };
function set(collection) {
setSeries.call(this, collection);
this._result = Array(this._rest);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
this._result[index] = value ? this._coll[index] : INTERNAL;
if (--this._rest === 0) {
this._promise._resolve(compactArray(this._result));
} else {
this._iterate();
}
}
function callResolveObject(value, index) {
this._result[index] = value ? this._coll[this._keys[index]] : INTERNAL;
if (--this._rest === 0) {
this._promise._resolve(compactArray(this._result));
} else {
this._iterate();
}
}
/**
* `Aigle.filterSeries` is almost the as [`Aigle.filter`](https://suguru03.github.io/aigle/docs/Aigle.html#filter), but it will work in series.
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.filterSeries(collection, iterator)
* .then(array => {
* console.log(array); // [1];
* console.log(order); // [1, 4, 2];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.filterSeries(collection, iterator)
* .then(array => {
* console.log(array); // [1];
* console.log(order); // [1, 4, 2];
* });
*/
function filterSeries(collection, iterator) {
return new FilterSeries(collection, iterator)._execute();
}
+130
View File
@@ -0,0 +1,130 @@
'use strict';
const { Each } = require('./each');
const { setShorthand } = require('./internal/collection');
class Find extends Each {
constructor(collection, iterator) {
super(collection, iterator, set);
}
}
module.exports = { find, Find };
function set(collection) {
setShorthand.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (value) {
this._size = 0;
this._promise._resolve(this._coll[index]);
} else if (--this._rest === 0) {
this._promise._resolve();
}
}
function callResolveObject(value, index) {
if (value) {
this._size = 0;
this._promise._resolve(this._coll[this._keys[index]]);
} else if (--this._rest === 0) {
this._promise._resolve();
}
}
/**
* `Aigle.find` has almost the same functionality as `Array#find`.
* It iterates all elements of `collection` and executes `iterator` using each element on parallel.
* The `iterator` needs to return a promise or something.
* If a promise is returned, the function will wait until the promise is fulfilled.
* If the result is truthly, the element will be returned as a result.
* @param {Array|Object} collection
* @param {Function|Array|Object|string} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2 === 0;
* });
* };
* Aigle.find(collection, iterator)
* .then(value => {
* console.log(value); // 2
* console.log(order); // [1, 2]
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2 === 0;
* });
* };
* Aigle.find(collection, iterator)
* .then(value => {
* console.log(value); // 2
* console.log(order); // [1, 2]
* });
*
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return false;
* });
* };
* Aigle.find(collection, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 2, 4]
* });
*
* @example
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.find(collection, 'active')
* .then(object => {
* console.log(object); // { name: 'fread', active: true }
* });
*
* @example
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.find(collection, ['name', 'fread'])
* .then(object => {
* console.log(object); // { name: 'fread', active: true }
* });
*
* @example
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.find(collection, { name: 'fread', active: true })
* .then(object => {
* console.log(object); // { name: 'fread', active: true }
* });
*/
function find(collection, iterator) {
return new Find(collection, iterator)._execute();
}
+104
View File
@@ -0,0 +1,104 @@
'use strict';
const { Each } = require('./each');
const { setShorthand } = require('./internal/collection');
class FindIndex extends Each {
constructor(collection, iterator) {
super(collection, iterator, set);
this._result = -1;
}
_callResolve(value, index) {
if (value) {
this._size = 0;
this._promise._resolve(index);
} else if (--this._rest === 0) {
this._promise._resolve(-1);
}
}
}
module.exports = { findIndex, FindIndex };
function set(collection) {
setShorthand.call(this, collection);
if (this._keys !== undefined) {
this._rest = 0;
}
return this;
}
/**
* `Aigle.findIndex` is like `Aigle.find`, it will return the index of the first element which the iterator returns truthy.
* @param {Array} collection
* @param {Function|Array|Object|string} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2 === 0;
* });
* };
* Aigle.findIndex(collection, iterator)
* .then(index => {
* console.log(index); // 2
* console.log(order); // [1, 2]
* });
*
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return false;
* });
* };
* Aigle.findIndex(collection, iterator)
* .then(index => {
* console.log(index); // -1
* console.log(order); // [1, 2, 4]
* });
*
* @example
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.findIndex(collection, 'active')
* .then(index => {
* console.log(index); // 1
* });
*
* @example
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.findIndex(collection, ['name', 'fread'])
* .then(index => {
* console.log(index); // true
* });
*
* @example
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.find(collection, { name: 'fread', active: true })
* .then(index => {
* console.log(index); // 1
* });
*/
function findIndex(collection, iterator) {
return new FindIndex(collection, iterator)._execute();
}
@@ -0,0 +1,75 @@
'use strict';
const { EachLimit } = require('./eachLimit');
const { setLimit } = require('./internal/collection');
class FindIndexLimit extends EachLimit {
constructor(collection, limit, iterator) {
super(collection, limit, iterator, set);
this._result = -1;
}
_callResolve(value, index) {
if (value) {
this._callRest = 0;
this._promise._resolve(index);
} else if (--this._rest === 0) {
this._promise._resolve(-1);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
}
module.exports = { findIndexLimit, FindIndexLimit };
function set(collection) {
setLimit.call(this, collection);
if (this._keys !== undefined) {
this._rest = 0;
}
return this;
}
/**
* `Aigle.findIndexLimit` is almost the as [`Aigle.findIndex`](https://suguru03.github.io/aigle/docs/Aigle.html#findIndex) and
* [`Aigle.findIndexSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#findIndexSeries), but it will work with concurrency.
* @param {Array} collection
* @param {integer} [limit=8]
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2 === 0;
* });
* };
* Aigle.findIndexLimit(collection, 2, iterator)
* .then(index => {
* console.log(index); // 4
* console.log(order); // [1, 3, 5, 2];
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2 === 0;
* });
* };
* Aigle.findIndexLimit(collection, iterator)
* .then(index => {
* console.log(index); // 4
* console.log(order); // [1, 2];
* });
*/
function findIndexLimit(collection, limit, iterator) {
return new FindIndexLimit(collection, limit, iterator)._execute();
}
@@ -0,0 +1,71 @@
'use strict';
const { EachSeries } = require('./eachSeries');
const { setSeries } = require('./internal/collection');
class FindIndexSeries extends EachSeries {
constructor(collection, iterator) {
super(collection, iterator, set);
this._result = -1;
}
_callResolve(value, index) {
if (value) {
this._promise._resolve(index);
} else if (--this._rest === 0) {
this._promise._resolve(-1);
} else {
this._iterate();
}
}
}
module.exports = { findIndexSeries, FindIndexSeries };
function set(collection) {
setSeries.call(this, collection);
if (this._keys !== undefined) {
this._rest = 0;
}
return this;
}
/**
* `Aigle.findIndexSeries` is almost the as [`Aigle.findIndex`](https://suguru03.github.io/aigle/docs/Aigle.html#findIndex), but it will work in series.
* @param {Array} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2 === 0;
* });
* };
* Aigle.findIndexSeries(collection, iterator)
* .then(index => {
* console.log(index); // 1
* console.log(order); // [1, 4];
* });
*
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return false;
* });
* };
* Aigle.findIndexSeries(collection, iterator)
* .then(index => {
* console.log(index); // -1
* console.log(order); // [1, 4, 2];
* });
*/
function findIndexSeries(collection, iterator) {
return new FindIndexSeries(collection, iterator)._execute();
}
+45
View File
@@ -0,0 +1,45 @@
'use strict';
const { Each } = require('./each');
const { setShorthand } = require('./internal/collection');
class FindKey extends Each {
constructor(collection, iterator) {
super(collection, iterator, set);
}
}
module.exports = { findKey, FindKey };
function set(collection) {
setShorthand.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (value) {
this._size = 0;
this._promise._resolve(`${index}`);
} else if (--this._rest === 0) {
this._promise._resolve();
}
}
function callResolveObject(value, index) {
if (value) {
this._size = 0;
this._promise._resolve(this._keys[index]);
} else if (--this._rest === 0) {
this._promise._resolve();
}
}
/**
* @param {Array|Object} collection
* @param {Function|Array|Object|string} iterator
* @return {Aigle} Returns an Aigle instance
*/
function findKey(collection, iterator) {
return new FindKey(collection, iterator)._execute();
}
+50
View File
@@ -0,0 +1,50 @@
'use strict';
const { EachLimit } = require('./eachLimit');
const { setLimit } = require('./internal/collection');
class FindKeyLimit extends EachLimit {
constructor(collection, limit, iterator) {
super(collection, limit, iterator, set);
}
}
module.exports = { findKeyLimit, FindKeyLimit };
function set(collection) {
setLimit.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (value) {
this._callRest = 0;
this._promise._resolve(`${index}`);
} else if (--this._rest === 0) {
this._promise._resolve();
} else if (this._callRest-- > 0) {
this._iterate();
}
}
function callResolveObject(value, index) {
if (value) {
this._callRest = 0;
this._promise._resolve(this._keys[index]);
} else if (--this._rest === 0) {
this._promise._resolve();
} else if (this._callRest-- > 0) {
this._iterate();
}
}
/**
* @param {Array|Object} collection
* @param {integer} [limit=8]
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
*/
function findKeyLimit(collection, limit, iterator) {
return new FindKeyLimit(collection, limit, iterator)._execute();
}
@@ -0,0 +1,47 @@
'use strict';
const { EachSeries } = require('./eachSeries');
const { setSeries } = require('./internal/collection');
class FindKeySeries extends EachSeries {
constructor(collection, iterator) {
super(collection, iterator, set);
}
}
module.exports = { findKeySeries, FindKeySeries };
function set(collection) {
setSeries.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (value) {
this._promise._resolve(`${index}`);
} else if (--this._rest === 0) {
this._promise._resolve();
} else {
this._iterate();
}
}
function callResolveObject(value, index) {
if (value) {
this._promise._resolve(this._keys[index]);
} else if (--this._rest === 0) {
this._promise._resolve();
} else {
this._iterate();
}
}
/**
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
*/
function findKeySeries(collection, iterator) {
return new FindKeySeries(collection, iterator)._execute();
}
+99
View File
@@ -0,0 +1,99 @@
'use strict';
const { EachLimit } = require('./eachLimit');
const { setLimit } = require('./internal/collection');
class FindLimit extends EachLimit {
constructor(collection, limit, iterator) {
super(collection, limit, iterator, set);
}
}
module.exports = { findLimit, FindLimit };
function set(collection) {
setLimit.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (value) {
this._callRest = 0;
this._promise._resolve(this._coll[index]);
} else if (--this._rest === 0) {
this._promise._resolve();
} else if (this._callRest-- > 0) {
this._iterate();
}
}
function callResolveObject(value, index) {
if (value) {
this._callRest = 0;
this._promise._resolve(this._coll[this._keys[index]]);
} else if (--this._rest === 0) {
this._promise._resolve();
} else if (this._callRest-- > 0) {
this._iterate();
}
}
/**
* `Aigle.findLimit` is almost the as [`Aigle.find`](https://suguru03.github.io/aigle/docs/Aigle.html#find) and
* [`Aigle.findSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#findSeries), but it will work with concurrency.
* @param {Array|Object} collection
* @param {integer} [limit=8]
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2 === 0;
* });
* };
* Aigle.findLimit(collection, 2, iterator)
* .then(value => {
* console.log(value); // 2
* console.log(order); // [1, 3, 5, 2];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2 === 0;
* });
* };
* Aigle.findLimit(collection, 2, iterator)
* .then(value => {
* console.log(value); // 2
* console.log(order); // [1, 3, 5, 2];
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2 === 0;
* });
* };
* Aigle.findLimit(collection, iterator)
* .then(value => {
* console.log(value); // 2
* console.log(order); // [1, 2];
* });
*/
function findLimit(collection, limit, iterator) {
return new FindLimit(collection, limit, iterator)._execute();
}
+95
View File
@@ -0,0 +1,95 @@
'use strict';
const { EachSeries } = require('./eachSeries');
const { setSeries } = require('./internal/collection');
class FindSeries extends EachSeries {
constructor(collection, iterator) {
super(collection, iterator, set);
}
}
module.exports = { findSeries, FindSeries };
function set(collection) {
setSeries.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (value) {
this._promise._resolve(this._coll[index]);
} else if (--this._rest === 0) {
this._promise._resolve();
} else {
this._iterate();
}
}
function callResolveObject(value, index) {
if (value) {
this._promise._resolve(this._coll[this._keys[index]]);
} else if (--this._rest === 0) {
this._promise._resolve();
} else {
this._iterate();
}
}
/**
* `Aigle.findSeries` is almost the as [`Aigle.find`](https://suguru03.github.io/aigle/docs/Aigle.html#find), but it will work in series.
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2 === 0;
* });
* };
* Aigle.findSeries(collection, iterator)
* .then(value => {
* console.log(value); // 4
* console.log(order); // [1, 4];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2 === 0;
* });
* };
* Aigle.findSeries(collection, iterator)
* .then(value => {
* console.log(value); // 4
* console.log(order); // [1, 4];
* });
*
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return false;
* });
* };
* Aigle.findSeries(collection, iterator)
* .then(value => {
* console.log(value); // undefined
* console.log(order); // [1, 4, 2];
* });
*/
function findSeries(collection, iterator) {
return new FindSeries(collection, iterator)._execute();
}
+39
View File
@@ -0,0 +1,39 @@
'use strict';
const Aigle = require('./aigle');
module.exports = flow;
/**
* @param {Function[]} funcs
* @return {Function} Returns the new composite function
* @example
* const add = (a, b) => Aigle.delay(10, a + b);
* const square = n => Aigle.delay(10, n * n);
* const addSquare = Aigle.flow(add, square);
* return addSquare(1, 2).then(value => {
* console.log(value); // 9
* });
*/
function flow(...funcs) {
const [handler = thru, ...handlers] = flatArray(funcs);
return (...args) =>
Aigle.resolve(handler(...args)).then(data =>
Aigle.reduce(handlers, (acc, func) => func(acc), data)
);
}
function thru(arg) {
return arg;
}
function flatArray(args) {
const l = args.length;
const array = [];
let i = -1;
while (++i < l) {
const arg = args[i];
Array.isArray(arg) ? array.push(...arg) : array.push(arg);
}
return array;
}
+113
View File
@@ -0,0 +1,113 @@
'use strict';
const { Each } = require('./each');
const { setShorthand } = require('./internal/collection');
class GroupBy extends Each {
constructor(collection, iterator) {
super(collection, iterator, set);
this._result = {};
}
}
module.exports = { groupBy, GroupBy };
function set(collection) {
setShorthand.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(key, index) {
if (this._result[key]) {
this._result[key].push(this._coll[index]);
} else {
this._result[key] = [this._coll[index]];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
function callResolveObject(key, index) {
if (this._result[key]) {
this._result[key].push(this._coll[this._keys[index]]);
} else {
this._result[key] = [this._coll[this._keys[index]]];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
/**
* @param {Array|Object} collection
* @param {Function|string} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.groupBy(collection, iterator)
* .then(object => {
* console.log(object); // { '0': [2, 4], '1': [1] };
* console.log(order); // [1, 2, 4];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.groupBy(collection, iterator)
* .then(object => {
* console.log(object); // { '0': [2, 4], '1': [1] };
* console.log(order); // [1, 2, 4];
* });
*
* @example
* const order = [];
* const collection = ['one', 'two', 'three'];
* Aigle.groupBy(collection, 'length')
* .then(object => {
* console.log(object); // { '3': ['one', 'two'], '5': ['three'] };
* });
*
* @example
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.groupBy(collection, ['active', true])
* .then(object => {
* console.log(object);
* // { 'true': [{ name: 'fread', active: true }], 'false': [{ name: 'bargey', active: false }];
* });
*
* @example
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.groupBy(collection, { active: true })
* .then(object => {
* console.log(object);
* // { 'true': [{ name: 'fread', active: true }], 'false': [{ name: 'bargey', active: false }];
* });
*/
function groupBy(collection, iterator) {
return new GroupBy(collection, iterator)._execute();
}
+108
View File
@@ -0,0 +1,108 @@
'use strict';
const { EachLimit } = require('./eachLimit');
const { setLimit } = require('./internal/collection');
class GroupByLimit extends EachLimit {
constructor(collection, limit, iterator) {
super(collection, limit, iterator, set);
this._result = {};
}
}
module.exports = { groupByLimit, GroupByLimit };
function set(collection) {
setLimit.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(key, index) {
if (this._result[key]) {
this._result[key].push(this._coll[index]);
} else {
this._result[key] = [this._coll[index]];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
function callResolveObject(key, index) {
if (this._result[key]) {
this._result[key].push(this._coll[this._keys[index]]);
} else {
this._result[key] = [this._coll[this._keys[index]]];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
/**
* @param {Array|Object} collection
* @param {integer} [limit=8]
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.groupByLimit(collection, 2, iterator)
* .then(object => {
* console.log(object); // { '0': [2, 4], '1': [1, 3, 5] };
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = {
* task1: 1,
* task2: 5,
* task3: 3,
* task4: 4,
* task5: 2
* };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.groupByLimit(collection, 2, iterator)
* .then(object => {
* console.log(object); // { '0': [2, 4], '1': [1, 3, 5] };
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.groupByLimit(collection, iterator)
* .then(object => {
* console.log(object); // { '0': [2, 4], '1': [1, 3, 5] };
* console.log(order); // [1, 2, 3, 4, 5];
* });
*/
function groupByLimit(collection, limit, iterator) {
return new GroupByLimit(collection, limit, iterator)._execute();
}
@@ -0,0 +1,85 @@
'use strict';
const { EachSeries } = require('./eachSeries');
const { setSeries } = require('./internal/collection');
class GroupBySeries extends EachSeries {
constructor(collection, iterator) {
super(collection, iterator, set);
this._result = {};
}
}
module.exports = { groupBySeries, GroupBySeries };
function set(collection) {
setSeries.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(key, index) {
if (this._result[key]) {
this._result[key].push(this._coll[index]);
} else {
this._result[key] = [this._coll[index]];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
function callResolveObject(key, index) {
if (this._result[key]) {
this._result[key].push(this._coll[this._keys[index]]);
} else {
this._result[key] = [this._coll[this._keys[index]]];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
/**
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.groupBySeries(collection, iterator)
* .then(object => {
* console.log(object); // { '0': [4, 2], '1': [1] };
* console.log(order); // [1, 4, 2];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.groupBySeries(collection, iterator)
* .then(object => {
* console.log(object); // { '0': [4, 2], '1': [1] };
* console.log(order); // [1, 4, 2];
* });
*/
function groupBySeries(collection, iterator) {
return new GroupBySeries(collection, iterator)._execute();
}
@@ -0,0 +1,33 @@
'use strict';
const queue = Array(8);
let len = 0;
let ticked = false;
function tick() {
let i = -1;
while (++i < len) {
const promise = queue[i];
queue[i] = undefined;
switch (promise._resolved) {
case 1:
promise._callResolve();
break;
case 2:
promise._callReject();
break;
}
}
len = 0;
ticked = false;
}
function invoke(promise) {
if (ticked === false) {
setImmediate(tick);
ticked = true;
}
queue[len++] = promise;
}
module.exports = invoke;
@@ -0,0 +1,302 @@
'use strict';
const { call3, callProxyReciever } = require('./util');
const [setParallel, setParallelWithOrder, setSeries] = [
[iterateArrayParallel, iterateObjectParallel],
[iterateArrayParallel, iterateObjectParallelWithOrder],
[iterateArraySeries, iterateObjectSeries]
].map(createSet);
const arrayIteratorList = [
iterateArrayParallel,
iterateArrayWithString,
iterateArrayWithObject,
iterateArrayWithArray
];
const objectIteratorList = [
iterateObjectParallel,
iterateObjectWithString,
iterateObjectWithObject,
iterateObjectWithArray
];
const [setShorthand, setShorthandWithOrder, setPickShorthand, setOmitShorthand] = [
[arrayIteratorList, objectIteratorList],
[arrayIteratorList, [iterateObjectParallelWithOrder, ...objectIteratorList.slice(1)]],
[
[...arrayIteratorList.slice(0, 3), iteratePickWithArray],
[...objectIteratorList.slice(0, 3), iteratePickWithArray]
],
[
[...arrayIteratorList.slice(0, 3), iterateOmitWithArray],
[...objectIteratorList.slice(0, 3), iterateOmitWithArray]
]
].map(createSetShorthand);
module.exports = {
execute,
setParallel,
setParallelWithOrder,
setShorthand,
setShorthandWithOrder,
setPickShorthand,
setOmitShorthand,
setSeries,
setLimit
};
function execute(collection) {
this._callResolve = this._iterate;
this._set(collection);
this._execute();
}
function createSet([iterateArray, iterateObject]) {
return function set(collection) {
if (Array.isArray(collection)) {
this._coll = collection;
this._size = collection.length;
this._iterate = iterateArray;
} else if (collection && typeof collection === 'object') {
const keys = Object.keys(collection);
this._coll = collection;
this._size = keys.length;
this._keys = keys;
this._iterate = iterateObject;
} else {
this._size = 0;
}
this._rest = this._size;
return this;
};
}
function createSetShorthand(list) {
const [getArrayIterator, getObjectIterator] = list.map(createIteratorGetter);
return function set(collection) {
if (Array.isArray(collection)) {
this._coll = collection;
this._size = collection.length;
this._iterate = getArrayIterator(this._iterator);
} else if (collection && typeof collection === 'object') {
const keys = Object.keys(collection);
this._coll = collection;
this._size = keys.length;
this._keys = keys;
this._iterate = getObjectIterator(this._iterator);
} else {
this._size = 0;
}
this._rest = this._size;
return this;
};
}
function createIteratorGetter([
iterateParallel,
iterateWithString,
iterateWithObject,
iterateWithArray
]) {
return iterator => {
switch (typeof iterator) {
case 'function':
return iterateParallel;
case 'string':
return iterateWithString;
case 'object':
return Array.isArray(iterator) ? iterateWithArray : iterateWithObject;
}
};
}
function setLimit(collection) {
setSeries.call(this, collection);
const { _limit, _size } = this;
this._limit = _limit < _size ? _limit : _size;
this._callRest = _size - this._limit;
return this;
}
function iterateArrayParallel() {
const { _rest, _iterator, _coll } = this;
let i = -1;
while (++i < _rest && callProxyReciever(call3(_iterator, _coll[i], i, _coll), this, i)) {}
}
function iterateObjectParallel() {
const { _rest, _iterator, _coll, _keys } = this;
let i = -1;
while (++i < _rest) {
const key = _keys[i];
if (callProxyReciever(call3(_iterator, _coll[key], key, _coll), this, i) === false) {
break;
}
}
}
function iterateObjectParallelWithOrder() {
const { _rest, _iterator, _coll, _keys, _result } = this;
let i = -1;
while (++i < _rest) {
const key = _keys[i];
_result[key] = undefined;
if (callProxyReciever(call3(_iterator, _coll[key], key, _coll), this, i) === false) {
break;
}
}
}
function iterateArraySeries() {
const { _coll } = this;
const i = this._index++;
callProxyReciever(call3(this._iterator, _coll[i], i, _coll), this, i);
}
function iterateObjectSeries() {
const { _coll } = this;
const i = this._index++;
const key = this._keys[i];
callProxyReciever(call3(this._iterator, _coll[key], key, _coll), this, i);
}
function iterateArrayWithString() {
const { _iterator, _coll } = this;
let i = -1;
while (++i < this._size) {
const obj = _coll[i];
if (obj) {
this._callResolve(obj[_iterator], i);
} else {
this._callResolve(undefined, i);
}
}
}
function iterateObjectWithString() {
const { _iterator, _coll, _keys } = this;
let i = -1;
while (++i < this._size) {
const obj = _coll[_keys[i]];
if (obj) {
this._callResolve(obj[_iterator], i);
} else {
this._callResolve(undefined, i);
}
}
}
function iterateArrayWithArray() {
const { _coll } = this;
const [key, value] = this._iterator;
let i = -1;
while (++i < this._size) {
const obj = _coll[i];
if (obj) {
this._callResolve(obj[key] === value, i);
} else {
this._callResolve(undefined, i);
}
}
}
function iterateObjectWithArray() {
const { _coll, _keys } = this;
const [key, value] = this._iterator;
let i = -1;
while (++i < this._size) {
const obj = _coll[_keys[i]];
if (obj) {
this._callResolve(obj[key] === value, i);
} else {
this._callResolve(undefined, i);
}
}
}
function iterateArrayWithObject() {
const { _iterator: object, _coll } = this;
const keys = Object.keys(object);
let i = -1;
first: while (++i < this._size) {
const obj = _coll[i];
if (!obj) {
this._callResolve(undefined, i);
continue;
}
let l = keys.length;
while (l--) {
const key = keys[l];
if (obj[key] !== object[key]) {
this._callResolve(false, i);
continue first;
}
}
this._callResolve(true, i);
}
}
function iterateObjectWithObject() {
const { _iterator: object, _coll, _keys } = this;
const keys = Object.keys(object);
let i = -1;
first: while (++i < this._size) {
const obj = _coll[_keys[i]];
if (!obj) {
this._callResolve(undefined, i);
continue;
}
let l = keys.length;
while (l--) {
const key = keys[l];
if (obj[key] !== object[key]) {
this._callResolve(false, i);
continue first;
}
}
this._callResolve(true, i);
}
}
function iteratePickWithArray() {
const { _coll, _result } = this;
pick(this._iterator);
this._promise._resolve(_result);
function pick(array) {
let i = -1;
while (++i < array.length) {
const key = array[i];
if (Array.isArray(key)) {
pick(key);
continue;
}
if (_coll.hasOwnProperty(key)) {
_result[key] = _coll[key];
}
}
}
}
function iterateOmitWithArray() {
const { _coll, _result } = this;
const map = {};
createMap(this._iterator);
Object.keys(_coll).forEach(key => {
if (map.hasOwnProperty(key) === false) {
_result[key] = _coll[key];
}
});
this._promise._resolve(_result);
function createMap(array) {
let i = -1;
while (++i < array.length) {
const key = array[i];
if (Array.isArray(key)) {
createMap(key);
continue;
}
map[key] = true;
}
}
}
@@ -0,0 +1,93 @@
'use strict';
const { AigleProxy } = require('aigle-core');
const Aigle = require('../aigle');
const { map } = require('../map');
const { mapValues } = require('../mapValues');
const { INTERNAL, PENDING, apply, callProxyReciever } = require('./util');
module.exports = { createProxy };
class MixinProxy extends AigleProxy {
constructor(func, exec, args) {
super();
this._promise = new Aigle(INTERNAL);
this._func = func;
this._args = args;
this._execute = exec;
if (args[0] === PENDING) {
this._set = this._callResolve;
this._callResolve = exec;
}
}
_callResolve(value) {
this._promise._resolve(value);
}
_callReject(reason) {
this._promise._reject(reason);
}
}
function execute(value) {
const { _args } = this;
if (_args[0] === PENDING) {
_args[0] = value;
this._callResolve = this._set;
}
callProxyReciever(apply(this._func, _args), this);
return this._promise;
}
function executeWithPromisify(value) {
const { _args } = this;
if (_args[0] === PENDING) {
_args[0] = value;
this._callResolve = this._set;
} else {
value = _args[0];
}
const iterator = _args[1];
const isFunc = typeof iterator === 'function';
if (isFunc && Array.isArray(value)) {
callIterator(this, map, array => {
let index = 0;
_args[1] = () => array[index++];
callProxyReciever(apply(this._func, _args), this);
});
} else if (isFunc && value && typeof value === 'object') {
callIterator(this, mapValues, object => {
let index = 0;
const keys = Object.keys(object);
_args[1] = () => object[keys[index++]];
callProxyReciever(apply(this._func, _args), this);
});
} else {
callProxyReciever(apply(this._func, _args), this);
}
return this._promise;
}
function callIterator(proxy, func, onFulfilled) {
const [collection, iterator] = proxy._args;
const p = func(collection, (value, key) => iterator(value, key, collection));
return p._resolved === 1
? onFulfilled(p._value)
: p.then(onFulfilled, error => proxy._callReject(error));
}
/**
* @private
* @param {function} func
* @param {boolean} promisify
*/
function createProxy(func, promisify) {
const exec = promisify ? executeWithPromisify : execute;
return class extends MixinProxy {
constructor(...args) {
super(func, exec, args);
}
};
}
@@ -0,0 +1,14 @@
'use strict';
class Queue {
constructor(size = 8) {
this.array = Array(size);
this.length = 0;
}
push(task) {
this.array[this.length++] = task;
}
}
module.exports = Queue;
+442
View File
@@ -0,0 +1,442 @@
'use strict';
const { AigleCore } = require('aigle-core');
const { version: VERSION } = require('../../package.json');
const DEFAULT_LIMIT = 8;
const errorObj = { e: undefined };
const iteratorSymbol = typeof Symbol === 'function' ? Symbol.iterator : function SYMBOL() {};
const isNode =
typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]';
const iterators = [
createArrayIterator,
createObjectIterator,
createSetIterator,
createMapIterator
].map(createIterator => [callProxyReciever, callProxyRecieverWithFunc].map(createIterator));
const [
[, promiseArrayIterator],
[, promiseObjectIterator],
[, promiseSetIterator],
[, promiseMapIterator]
] = iterators;
const [
[promiseArrayEach, promiseArrayEachWithFunc],
[promiseObjectEach, promiseObjectEachWithFunc],
[promiseSetEach, promiseSetEachWithFunc],
[promiseMapEach, promiseMapEachWithFunc]
] = [createArrayEach, createObjectEach, createSetEach, createMapEach].map((createEach, index) =>
iterators[index].map(createEach)
);
module.exports = {
VERSION,
DEFAULT_LIMIT,
INTERNAL,
PENDING,
UNHANDLED,
defaultIterator,
errorObj,
iteratorSymbol,
call0,
call1,
call3,
apply,
callResolve,
callReject,
callReceiver,
callThen,
callProxyReciever,
callProxyRecieverWithFunc,
promiseArrayIterator,
promiseArrayEach,
promiseArrayEachWithFunc,
promiseObjectIterator,
promiseObjectEach,
promiseObjectEachWithFunc,
promiseSetIterator,
promiseSetEach,
promiseSetEachWithFunc,
promiseMapIterator,
promiseMapEach,
promiseMapEachWithFunc,
compactArray,
concatArray,
clone,
createEmptyObject,
sortArray,
sortObject,
printWarning
};
function INTERNAL() {}
function PENDING() {}
function UNHANDLED() {}
function defaultIterator(n) {
return n;
}
function call0(handler) {
try {
return handler();
} catch (e) {
errorObj.e = e;
return errorObj;
}
}
function call1(handler, value) {
try {
return handler(value);
} catch (e) {
errorObj.e = e;
return errorObj;
}
}
function call3(handler, arg1, arg2, arg3) {
try {
return handler(arg1, arg2, arg3);
} catch (e) {
errorObj.e = e;
return errorObj;
}
}
function apply(handler, array) {
try {
switch (array.length) {
case 0:
return handler();
case 1:
return handler(array[0]);
case 2:
return handler(array[0], array[1]);
case 3:
return handler(array[0], array[1], array[2]);
default:
return handler.apply(null, array);
}
} catch (e) {
errorObj.e = e;
return errorObj;
}
}
function callResolve(receiver, onFulfilled, value) {
typeof onFulfilled === 'function'
? callReceiver(receiver, call1(onFulfilled, value))
: receiver._resolve(value);
}
function callReject(receiver, onRejected, reason) {
typeof onRejected === 'function'
? callReceiver(receiver, call1(onRejected, reason))
: receiver._reject(reason);
}
function callReceiver(receiver, promise) {
if (promise === errorObj) {
receiver._reject(errorObj.e);
return;
}
if (!promise || !promise.then) {
receiver._resolve(promise);
return;
}
if (promise instanceof AigleCore) {
switch (promise._resolved) {
case 0:
promise._addReceiver(receiver, INTERNAL);
return;
case 1:
receiver._resolve(promise._value);
return;
case 2:
promise.suppressUnhandledRejections();
receiver._reject(promise._value);
return;
}
}
callThen(promise, receiver);
}
function callThen(promise, receiver) {
promise.then(resolve, reject);
function resolve(value) {
receiver._resolve(value);
}
function reject(reason) {
receiver._reject(reason);
}
}
function callProxyThen(promise, receiver, key) {
promise.then(resolve, reject);
function resolve(value) {
receiver._callResolve(value, key);
}
function reject(reason) {
receiver._callReject(reason, key);
}
}
function callProxyReciever(promise, receiver, key) {
if (promise instanceof AigleCore) {
switch (promise._resolved) {
case 0:
promise._addReceiver(receiver, key);
return true;
case 1:
receiver._callResolve(promise._value, key);
return true;
case 2:
promise.suppressUnhandledRejections();
return receiver._callReject(promise._value, key) === true;
}
}
if (promise === errorObj) {
return receiver._callReject(errorObj.e, key) === true;
}
if (promise && promise.then) {
callProxyThen(promise, receiver, key);
} else {
receiver._callResolve(promise, key);
}
return true;
}
function callProxyRecieverWithFunc(promise, receiver, index) {
if (typeof promise === 'function') {
promise = promise();
}
return callProxyReciever(promise, receiver, index);
}
function createArrayIterator(handler) {
return (receiver, coll, index) => handler(coll[index], receiver, index);
}
function createArrayEach(iterator) {
return (receiver, times, coll) => {
let i = -1;
while (++i < times && iterator(receiver, coll, i)) {}
};
}
function createObjectIterator(handler) {
return (receiver, coll, index, result, keys) => {
const key = keys[index];
result[key] = undefined;
return handler(coll[key], receiver, key);
};
}
function createObjectEach(iterator) {
return (receiver, times, coll, result, keys) => {
let i = -1;
while (++i < times && iterator(receiver, coll, i, result, keys)) {}
};
}
function createSetIterator(handler) {
return (receiver, iter, index) => {
const item = iter.next();
return item.done === false && handler(item.value, receiver, index);
};
}
function createSetEach(iterator) {
return (receiver, times, coll) => {
const iter = coll[iteratorSymbol]();
let i = -1;
while (++i < times && iterator(receiver, iter, i)) {}
};
}
function createMapIterator(handler) {
return (receiver, iter, index, result) => {
const item = iter.next();
if (item.done) {
return false;
}
const [key, promise] = item.value;
result.set(key, undefined);
return handler(promise, receiver, key);
};
}
function createMapEach(iterator) {
return (receiver, times, coll, result) => {
const iter = coll[iteratorSymbol]();
let i = -1;
while (++i < times && iterator(receiver, iter, i, result)) {}
};
}
function compactArray(array) {
let i = -1;
const l = array.length;
const result = [];
while (++i < l) {
const value = array[i];
if (value !== INTERNAL) {
result.push(value);
}
}
return result;
}
function concatArray(array) {
let i = -1;
const l = array.length;
const result = [];
while (++i < l) {
const value = array[i];
if (Array.isArray(value)) {
result.push(...value);
} else if (value !== undefined) {
result.push(value);
}
}
return result;
}
function clone(target) {
return Array.isArray(target) ? cloneArray(target) : cloneObject(target);
}
function cloneArray(array) {
let l = array.length;
const result = Array(l);
while (l--) {
result[l] = array[l];
}
return result;
}
function cloneObject(object) {
const keys = Object.keys(object);
let l = keys.length;
const result = {};
while (l--) {
const key = keys[l];
result[key] = object[key];
}
return result;
}
function createEmptyObject(object, keys) {
let i = -1;
const l = keys.length;
const result = {};
while (++i < l) {
result[keys[i]] = undefined;
}
return result;
}
/**
* @private
* @param {Array} array
* @param {number[]} criteria
*/
function sortArray(array, criteria) {
const l = array.length;
const indices = Array(l);
for (let i = 0; i < l; i++) {
indices[i] = i;
}
quickSort(criteria, 0, l - 1, indices);
const result = Array(l);
for (let n = 0; n < l; n++) {
const i = indices[n];
result[n] = i === undefined ? array[n] : array[i];
}
return result;
}
/**
* @private
* @param {Object} object
* @param {string[]} keys
* @param {number[]} criteria
*/
function sortObject(object, keys, criteria) {
const l = keys.length;
const indices = Array(l);
for (let i = 0; i < l; i++) {
indices[i] = i;
}
quickSort(criteria, 0, l - 1, indices);
const result = Array(l);
for (let n = 0; n < l; n++) {
const i = indices[n];
result[n] = object[keys[i === undefined ? n : i]];
}
return result;
}
function partition(array, i, j, mid, indices) {
let l = i;
let r = j;
while (l <= r) {
i = l;
while (l < r && array[l] < mid) {
l++;
}
while (r >= i && array[r] >= mid) {
r--;
}
if (l > r) {
break;
}
swap(array, indices, l++, r--);
}
return l;
}
function swap(array, indices, l, r) {
const n = array[l];
array[l] = array[r];
array[r] = n;
const i = indices[l];
indices[l] = indices[r];
indices[r] = i;
}
function quickSort(array, i, j, indices) {
if (i === j) {
return;
}
let k = i;
while (++k <= j && array[i] === array[k]) {
const l = k - 1;
if (indices[l] > indices[k]) {
const i = indices[l];
indices[l] = indices[k];
indices[k] = i;
}
}
if (k > j) {
return;
}
const p = array[i] > array[k] ? i : k;
k = partition(array, i, j, array[p], indices);
quickSort(array, i, k - 1, indices);
quickSort(array, k, j, indices);
}
function printWarning(message) {
isNode
? console.warn(`\u001b[31m${message}\u001b[0m\n`)
: console.warn(`%c${message}`, 'color: red');
}
+111
View File
@@ -0,0 +1,111 @@
'use strict';
const { AigleProxy } = require('aigle-core');
const Aigle = require('./aigle');
const { INTERNAL, call1, apply, callProxyReciever } = require('./internal/util');
class Join extends AigleProxy {
constructor(handler, size) {
super();
this._promise = new Aigle(INTERNAL);
this._rest = size;
this._result = Array(size);
this._handler = handler;
}
_callResolve(value, index) {
if (index === INTERNAL) {
return this._promise._resolve(value);
}
this._result[index] = value;
if (--this._rest !== 0) {
return;
}
const { _handler, _result } = this;
if (_handler === undefined) {
this._promise._resolve(_result);
} else {
callProxyReciever(apply(_handler, _result), this, INTERNAL);
}
}
_callReject(reason) {
this._promise._reject(reason);
}
}
class Spread extends AigleProxy {
constructor(handler) {
super();
this._promise = new Aigle(INTERNAL);
this._handler = handler;
}
_callResolve(value, index) {
if (index === INTERNAL) {
return this._promise._resolve(value);
}
spread(this, value);
}
_callReject(reason) {
this._promise._reject(reason);
}
}
module.exports = { join, Spread };
/**
* @example
* const p1 = Aigle.delay(20).then(() => 1);
* const p2 = Aigle.delay(10).then(() => 2);
* Aigle.join(p1, p2, (v1, v2) => {
* console.log(v1, v2); // 1 2
* });
*/
function join() {
let l = arguments.length;
const handler = typeof arguments[l - 1] === 'function' ? arguments[--l] : undefined;
const receiver = new Join(handler, l);
while (l--) {
callProxyReciever(arguments[l], receiver, l);
}
return receiver._promise;
}
/**
* @private
* @param {AigleProxy} proxy
* @param {string|Array|Object} array
*/
function spread(proxy, array) {
const { _handler } = proxy;
if (_handler === undefined) {
return proxy._promise._resolve(array);
}
switch (typeof array) {
case 'string':
array = array.split('');
break;
case 'object':
if (Array.isArray(array)) {
break;
}
if (array) {
const keys = Object.keys(array);
let l = keys.length;
const arr = Array(l);
while (l--) {
arr[l] = array[keys[l]];
}
array = arr;
break;
}
/* eslint no-fallthrough: 0 */
default:
/* eslint no-fallthrough: 1 */
return callProxyReciever(call1(_handler, array), proxy, INTERNAL);
}
callProxyReciever(apply(_handler, array), proxy, INTERNAL);
}
+81
View File
@@ -0,0 +1,81 @@
'use strict';
const { Each } = require('./each');
const { setShorthand } = require('./internal/collection');
class Map extends Each {
constructor(collection, iterator) {
super(collection, iterator, set);
}
_callResolve(value, index) {
this._result[index] = value;
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
}
module.exports = { map, Map };
function set(collection) {
setShorthand.call(this, collection);
this._result = Array(this._rest);
return this;
}
/**
* `Aigle.map` has almost the same functionality as `Array#map`.
* It iterates all elements of `collection` and executes `iterator` using each element on parallel.
* The `iterator` needs to return a promise or something.
* Then the result will be assigned to an array and the array order will be ensured.
* All of them are finished, the function will return an array as a result.
* @param {Array|Object} collection
* @param {Function|string} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.map(collection, iterator)
* .then(array => {
* console.log(array); // [2, 8, 4];
* console.log(order); // [1, 2, 4];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.map(collection, iterator)
* .then(array => {
* console.log(array); // [2, 8, 4];
* console.log(order); // [1, 2, 4];
* });
*
* @example
* const collection = [{
* uid: 1, name: 'test1'
* }, {
* uid: 4, name: 'test4'
* }, {
* uid: 2, name: 'test2'
* }];
* Aigle.map(collection, 'uid')
* .then(uids => console.log(uids)); // [1, 4, 2]
*/
function map(collection, iterator) {
return new Map(collection, iterator)._execute();
}
+86
View File
@@ -0,0 +1,86 @@
'use strict';
const { EachLimit } = require('./eachLimit');
const { setLimit } = require('./internal/collection');
class MapLimit extends EachLimit {
constructor(collection, limit, iterator) {
super(collection, limit, iterator, set);
}
_callResolve(value, index) {
this._result[index] = value;
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
}
module.exports = { mapLimit, MapLimit };
function set(collection) {
setLimit.call(this, collection);
this._result = Array(this._rest);
return this;
}
/**
* `Aigle.mapLimit` is almost the smae as [`Aigle.map`](https://suguru03.github.io/aigle/docs/Aigle.html#map) and
* [`Aigle.mapSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#mapSeries), but it will work with concurrency.
* @param {Array|Object} collection
* @param {integer} [limit=8]
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapLimit(collection, 2, iterator)
* .then(array => {
* console.log(array); // [2, 10, 6, 8, 4];
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapLimit(collection, 2, iterator)
* .then(array => {
* console.log(array); // [2, 10, 6, 8, 4];
* console.log(order); // [1, 3, 5, 2, 4];
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapLimit(collection, iterator)
* .then(array => {
* console.log(array); // [2, 10, 6, 8, 4];
* console.log(order); // [1, 2, 3, 4, 5];
* });
*/
function mapLimit(collection, limit, iterator) {
return new MapLimit(collection, limit, iterator)._execute();
}
+68
View File
@@ -0,0 +1,68 @@
'use strict';
const { EachSeries } = require('./eachSeries');
const { setSeries } = require('./internal/collection');
class MapSeries extends EachSeries {
constructor(collection, iterator) {
super(collection, iterator, set);
}
_callResolve(value, index) {
this._result[index] = value;
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
}
module.exports = { mapSeries, MapSeries };
function set(collection) {
setSeries.call(this, collection);
this._result = Array(this._rest);
return this;
}
/**
* `Aigle.mapSeries` is almost the smae as [`Aigle.map`](https://suguru03.github.io/aigle/docs/Aigle.html#map), but it will work in series.
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapSeries(collection, iterator)
* .then(array => {
* console.log(array); // [2, 8, 4];
* console.log(order); // [1, 4, 2];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapSeries(collection, iterator)
* .then(array => {
* console.log(array); // [2, 8, 4];
* console.log(order); // [1, 4, 2];
* });
*/
function mapSeries(collection, iterator) {
return new MapSeries(collection, iterator)._execute();
}
+84
View File
@@ -0,0 +1,84 @@
'use strict';
const { Each } = require('./each');
const { setShorthandWithOrder } = require('./internal/collection');
class MapValues extends Each {
constructor(collection, iterator) {
super(collection, iterator, set);
this._result = {};
}
}
module.exports = { mapValues, MapValues };
function set(collection) {
setShorthandWithOrder.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
this._result[index] = value;
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
function callResolveObject(value, index) {
this._result[this._keys[index]] = value;
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
/**
* `Aigle.mapValues` is similar to [`Aigle.map`](https://suguru03.github.io/aigle/docs/global.html#map).
* It returns an object instead of an array.
* @param {Array|Object} collection
* @param {Function|string} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapValues(collection, iterator)
* .then(object => {
* console.log(object); // { '0': 2, '1': 8, '2': 4 }
* console.log(order); // [1, 2, 4]
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapValues(collection, iterator)
* .then(object => {
* console.log(object); // { a: 2, b: 8, c: 4 }
* console.log(order); // [1, 2, 4]
* });
*
* @example
* const collection = {
* task1: { uid: 1, name: 'test1' },
* task2: { uid: 4, name: 'test4' },
* task3: { uid: 2, name: 'test2' }
* }];
* Aigle.mapValues(collection, 'uid')
* .then(uids => console.log(uids)); // { task1: 1, task2: 4, task3: 2 }
*/
function mapValues(collection, iterator) {
return new MapValues(collection, iterator)._execute();
}
@@ -0,0 +1,102 @@
'use strict';
const { EachLimit } = require('./eachLimit');
const { setLimit } = require('./internal/collection');
const { createEmptyObject } = require('./internal/util');
class MapValuesLimit extends EachLimit {
constructor(collection, limit, iterator) {
super(collection, limit, iterator, set);
}
}
module.exports = { mapValuesLimit, MapValuesLimit };
function set(collection) {
setLimit.call(this, collection);
if (this._keys === undefined) {
this._result = {};
this._callResolve = callResolveArray;
} else {
this._result = createEmptyObject(collection, this._keys);
this._callResolve = callResolveObject;
}
return this;
}
function callResolveArray(value, index) {
this._result[index] = value;
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
function callResolveObject(value, index) {
this._result[this._keys[index]] = value;
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
/**
* `Aigle.mapValuesLimit` is almost the same as [`Aigle.mapValues`](https://suguru03.github.io/aigle/docs/Aigle.html#mapValues) and
* [`Aigle.mapValuesSeries`](https://suguru03.github.io/aigle/docs/Aigle.html#mapValuesSeries), but it will work with concurrency.
* @param {Array|Object} collection
* @param {integer} [limit=8]
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapValuesLimit(collection, 2, iterator)
* .then(object => {
* console.log(object); // { '0': 2, '1': 10, '2': 6, '3': 8, '4': 4 }
* console.log(order); // [1, 3, 5, 2, 4]
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapValuesLimit(collection, 2, iterator)
* .then(object => {
* console.log(object); // { a: 2, b: 10, c: 6, d: 8, e: 4 }
* console.log(order); // [1, 3, 5, 2, 4]
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapValuesLimit(collection, iterator)
* .then(object => {
* console.log(object); // { '0': 2, '1': 10, '2': 6, '3': 8, '4': 4 }
* console.log(order); // [1, 2, 3, 4, 5]
* });
*/
function mapValuesLimit(collection, limit, iterator) {
return new MapValuesLimit(collection, limit, iterator)._execute();
}
@@ -0,0 +1,78 @@
'use strict';
const { EachSeries } = require('./eachSeries');
const { setSeries } = require('./internal/collection');
class MapValuesSeries extends EachSeries {
constructor(collection, iterator) {
super(collection, iterator, set);
this._result = {};
}
}
module.exports = { mapValuesSeries, MapValuesSeries };
function set(collection) {
setSeries.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
this._result[index] = value;
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
function callResolveObject(value, index) {
this._result[this._keys[index]] = value;
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
/**
* `Aigle.mapValuesSeries` is almost the same as [`Aigle.mapValues`](https://suguru03.github.io/aigle/docs/Aigle.html#mapValues), but it will work in series.
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapValuesSeries(collection, iterator)
* .then(object => {
* console.log(object); // { '0': 2, '1': 8, '2': 4 };
* console.log(order); // [1, 4, 2];
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.mapValuesSeries(collection, iterator)
* .then(object => {
* console.log(object); // { a: 2, b: 8, c: 4 }
* console.log(order); // [1, 4, 2];
* });
*/
function mapValuesSeries(collection, iterator) {
return new MapValuesSeries(collection, iterator)._execute();
}
+85
View File
@@ -0,0 +1,85 @@
'use strict';
const { Each } = require('./each');
const { setOmitShorthand } = require('./internal/collection');
class Omit extends Each {
constructor(collection, iterator, args) {
if (typeof iterator !== 'function') {
iterator = [iterator, ...args];
}
super(collection, iterator, set);
this._result = {};
}
}
module.exports = { omit, Omit };
function set(collection) {
setOmitShorthand.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (!value) {
this._result[index] = this._coll[index];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
function callResolveObject(value, index) {
if (!value) {
const key = this._keys[index];
this._result[key] = this._coll[key];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
/**
* `Aigle.omit` has almost the same functionality as [`Aigle.filter`](https://suguru03.github.io/aigle/docs/global.html#filter).
* It will return an object as a result.
* @param {Array|Object} collection
* @param {Function|Array|Object|string} iterator
* @param {*} [args]
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.omit(collection, iterator)
* .then(object => {
* console.log(object); // { '0': 1 }
* console.log(order); // [1, 2, 4]
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.omit(collection, iterator)
* .then(object => {
* console.log(object); // { a: 1 }
* console.log(order); // [1, 2, 4]
* });
*
*/
function omit(collection, iterator, ...args) {
return new Omit(collection, iterator, args)._execute();
}
+116
View File
@@ -0,0 +1,116 @@
'use strict';
const { Each } = require('./each');
const { setShorthand } = require('./internal/collection');
class OmitBy extends Each {
constructor(collection, iterator) {
super(collection, iterator, set);
this._result = {};
}
}
module.exports = { omitBy, OmitBy };
function set(collection) {
setShorthand.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (!value) {
this._result[index] = this._coll[index];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
function callResolveObject(value, index) {
if (!value) {
const key = this._keys[index];
this._result[key] = this._coll[key];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
/**
* `Aigle.omitBy` has almost the same functionality as [`Aigle.reject`](https://suguru03.github.io/aigle/docs/global.html#reject).
* It will return an object as a result.
* @param {Array|Object} collection
* @param {Function|Array|Object|string} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.omitBy(collection, iterator)
* .then(object => {
* console.log(object); // { '1': 4, '2': 4 }
* console.log(order); // [1, 2, 4]
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.omitBy(collection, iterator)
* .then(object => {
* console.log(object); // { b: 4, c: 2 }
* console.log(order); // [1, 2, 4]
* });
*
* @example
* const order = [];
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.omitBy(collection, 'active')
* .then(object => {
* console.log(object); // { '0': { name: 'bargey', active: false } }
* });
*
* @example
* const order = [];
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.omitBy(collection, ['name', 'fread'])
* .then(object => {
* console.log(object); // { '0': { name: 'bargey', active: false } }
* });
*
* @example
* const order = [];
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.omitBy(collection, { name: 'fread', active: true })
* .then(object => {
* console.log(object); // { '0': { name: 'bargey', active: false } }
* });
*/
function omitBy(collection, iterator) {
return new OmitBy(collection, iterator)._execute();
}
+101
View File
@@ -0,0 +1,101 @@
'use strict';
const { EachLimit } = require('./eachLimit');
const { setLimit } = require('./internal/collection');
class OmitByLimit extends EachLimit {
constructor(collection, limit, iterator) {
super(collection, limit, iterator, set);
this._result = {};
}
}
module.exports = { omitByLimit, OmitByLimit };
function set(collection) {
setLimit.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (!value) {
this._result[index] = this._coll[index];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
function callResolveObject(value, index) {
if (!value) {
const key = this._keys[index];
this._result[key] = this._coll[key];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
/**
* `Aigle.omitByLimit` is almost the as [`Aigle.omitBy`](https://suguru03.github.io/aigle/docs/Aigle.html#omitBy) and
* [`Aigle.omitBySeries`](https://suguru03.github.io/aigle/docs/Aigle.html#omitBySeries), but it will work with concurrency.
* @param {Array|Object} collection
* @param {integer} [limit=8]
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.omitByLimit(collection, 2, iterator)
* .then(object => {
* console.log(object); // { '3': 4, '4': 2 }
* console.log(order); // [1, 3, 5, 2, 4]
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.omitByLimit(collection, 2, iterator)
* .then(object => {
* console.log(object); // { d: 4, e: 2 }
* console.log(order); // [1, 3, 5, 2, 4]
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.omitByLimit(collection, iterator)
* .then(object => {
* console.log(object); // { '3': 4, '4': 2 }
* console.log(order); // [1, 2, 3, 4, 5]
* });
*/
function omitByLimit(collection, limit, iterator) {
return new OmitByLimit(collection, limit, iterator)._execute();
}
+89
View File
@@ -0,0 +1,89 @@
'use strict';
const { EachSeries } = require('./eachSeries');
const { PENDING } = require('./internal/util');
const { setSeries } = require('./internal/collection');
class OmitBySeries extends EachSeries {
constructor(collection, iterator) {
super(collection, iterator);
this._result = {};
if (collection === PENDING) {
this._set = set;
} else {
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
}
}
}
module.exports = { omitBySeries, OmitBySeries };
function set(collection) {
setSeries.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (!value) {
this._result[index] = this._coll[index];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
function callResolveObject(value, index) {
if (!value) {
const key = this._keys[index];
this._result[key] = this._coll[key];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
/**
* `Aigle.omitBySeries` is almost the as [`Aigle.omitBy`](https://suguru03.github.io/aigle/docs/Aigle.html#omitBy), but it will work in series.
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.omitBySeriesSeries(collection, iterator)
* .then(object => {
* console.log(object); // { '1': 4, '2': 2 }
* console.log(order); // [1, 4, 2]
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.omitBySeriesSeries(collection, iterator)
* .then(object => {
* console.log(object); // { b: 4, c: 2 }
* console.log(order); // [1, 4, 2]
* });
*/
function omitBySeries(collection, iterator) {
return new OmitBySeries(collection, iterator)._execute();
}
+104
View File
@@ -0,0 +1,104 @@
'use strict';
const { AigleProxy } = require('aigle-core');
const Aigle = require('./aigle');
const {
INTERNAL,
PENDING,
promiseArrayEachWithFunc,
promiseObjectEachWithFunc,
promiseMapEachWithFunc,
promiseSetEachWithFunc,
iteratorSymbol
} = require('./internal/util');
const { callResolve, callResolveMap } = require('./props');
class Parallel extends AigleProxy {
constructor(coll) {
super();
this._promise = new Aigle(INTERNAL);
this._rest = undefined;
this._result = undefined;
if (coll === PENDING) {
this._callResolve = this._set;
} else {
this._callResolve = undefined;
this._set(coll);
}
}
_set(coll) {
if (Array.isArray(coll)) {
const size = coll.length;
this._rest = size;
this._result = Array(size);
this._callResolve = callResolve;
promiseArrayEachWithFunc(this, size, coll);
} else if (!coll || typeof coll !== 'object') {
this._rest = 0;
this._result = {};
} else if (coll[iteratorSymbol]) {
const size = coll.size;
this._rest = size;
if (coll instanceof Map) {
const result = new Map();
this._result = result;
this._callResolve = callResolveMap;
promiseMapEachWithFunc(this, Infinity, coll, result);
} else {
this._result = Array(this._rest);
this._callResolve = callResolve;
promiseSetEachWithFunc(this, Infinity, coll);
}
} else {
const result = {};
const keys = Object.keys(coll);
const size = keys.length;
this._rest = size;
this._result = result;
this._callResolve = callResolve;
promiseObjectEachWithFunc(this, size, coll, result, keys);
}
if (this._rest === 0) {
this._promise._resolve(this._result);
}
return this;
}
_execute() {
return this._promise;
}
_callReject(reason) {
this._promise._reject(reason);
}
}
module.exports = { parallel, Parallel };
/**
* `Aigle.parallel` functionality is similar to [`Aigle.all`](https://suguru03.github.io/aigle/docs/global.html#all)
* and [`Aigle.props`](https://suguru03.github.io/aigle/docs/global.html#props), and the function allows function collection.
* @param {Array|Object} collection - it should be an array/object of functions or Promise instances
* @example
* Aigle.parallel([
* () => Aigle.delay(30, 1),
* Aigle.delay(20, 2),
* 3
* ]).then(array => {
* console.log(array); // [1, 2, 3]
* });
*
* @example
* Aigle.parallel({
* a: () => Aigle.delay(30, 1),
* b: Aigle.delay(20, 2),
* c: 3
* }).then(obj => {
* console.log(obj); // { a: 1, b: 2, c: 3 }
* });
*/
function parallel(collection) {
return new Parallel(collection)._promise;
}
@@ -0,0 +1,83 @@
'use strict';
const { Series } = require('./series');
const { DEFAULT_LIMIT } = require('./internal/util');
class ParallelLimit extends Series {
constructor(coll, limit = DEFAULT_LIMIT) {
super(coll);
this._size = this._rest;
this._limit = limit;
}
_execute() {
const { _limit, _rest } = this;
if (_rest === 0) {
this._promise._resolve(this._result);
return this._promise;
}
this._size = _rest;
this._iterate = iterate;
let limit = _limit < _rest ? _limit : _rest;
while (limit--) {
this._iterate();
}
return this._promise;
}
_callResolve(value, key) {
this._result[key] = value;
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
_callResolveMap(value, key) {
this._result.set(key, value);
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
_callReject(reason) {
this._promise._reject(reason);
}
}
module.exports = { parallelLimit, ParallelLimit };
function iterate() {
++this._index < this._size &&
this._iterator(this, this._coll, this._index, this._result, this._keys);
}
/**
* `Aigle.parallel` functionality has the same functionality as [`Aigle.parallel`](https://suguru03.github.io/aigle/docs/global.html#parallel)
* and it works with concurrency.
* @param {Array|Object} collection - it should be an array/object of functions or Promise instances
* @param {integer} [limit=8] - It is concurrncy, default is 8
* @example
* Aigle.parallelLimit([
* () => Aigle.delay(30, 1),
* Aigle.delay(20, 2),
* 3
* ]).then(array => {
* console.log(array); // [1, 2, 3]
* });
*
* @example
* Aigle.parallelLimit({
* a: () => Aigle.delay(30, 1),
* b: Aigle.delay(20, 2),
* c: 3
* }, 2).then(obj => {
* console.log(obj); // { a: 1, b: 2, c: 3 }
* });
*/
function parallelLimit(collection, limit) {
return new ParallelLimit(collection, limit)._execute();
}
+85
View File
@@ -0,0 +1,85 @@
'use strict';
const { Each } = require('./each');
const { setPickShorthand } = require('./internal/collection');
class Pick extends Each {
constructor(collection, iterator, args) {
if (typeof iterator !== 'function') {
iterator = [iterator, ...args];
}
super(collection, iterator, set);
this._result = {};
}
}
module.exports = { pick, Pick };
function set(collection) {
setPickShorthand.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (value) {
this._result[index] = this._coll[index];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
function callResolveObject(value, index) {
if (value) {
const key = this._keys[index];
this._result[key] = this._coll[key];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
/**
* `Aigle.pick` has almost the same functionality as [`Aigle.filter`](https://suguru03.github.io/aigle/docs/global.html#filter).
* It will return an object as a result.
* @param {Array|Object} collection
* @param {Function|Array|Object|string} iterator
* @param {*} [args]
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.pick(collection, iterator)
* .then(object => {
* console.log(object); // { '0': 1 }
* console.log(order); // [1, 2, 4]
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.pick(collection, iterator)
* .then(object => {
* console.log(object); // { a: 1 }
* console.log(order); // [1, 2, 4]
* });
*
*/
function pick(collection, iterator, ...args) {
return new Pick(collection, iterator, args)._execute();
}
+116
View File
@@ -0,0 +1,116 @@
'use strict';
const { Each } = require('./each');
const { setShorthand } = require('./internal/collection');
class PickBy extends Each {
constructor(collection, iterator) {
super(collection, iterator, set);
this._result = {};
}
}
module.exports = { pickBy, PickBy };
function set(collection) {
setShorthand.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (value) {
this._result[index] = this._coll[index];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
function callResolveObject(value, index) {
if (value) {
const key = this._keys[index];
this._result[key] = this._coll[key];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
}
}
/**
* `Aigle.pickBy` has almost the same functionality as [`Aigle.filter`](https://suguru03.github.io/aigle/docs/global.html#filter).
* It will return an object as a result.
* @param {Array|Object} collection
* @param {Function|Array|Object|string} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.pickBy(collection, iterator)
* .then(object => {
* console.log(object); // { '0': 1 }
* console.log(order); // [1, 2, 4]
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.pickBy(collection, iterator)
* .then(object => {
* console.log(object); // { a: 1 }
* console.log(order); // [1, 2, 4]
* });
*
* @example
* const order = [];
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.pickBy(collection, 'active')
* .then(object => {
* console.log(object); // { '1': { name: 'fread', active: true } }
* });
*
* @example
* const order = [];
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.pickBy(collection, ['name', 'fread'])
* .then(object => {
* console.log(object); // { '1': { name: 'fread', active: true } }
* });
*
* @example
* const order = [];
* const collection = [{
* name: 'bargey', active: false
* }, {
* name: 'fread', active: true
* }];
* Aigle.pickBy(collection, { name: 'fread', active: true })
* .then(object => {
* console.log(object); // { '1': { name: 'fread', active: true } }
* });
*/
function pickBy(collection, iterator) {
return new PickBy(collection, iterator)._execute();
}
+101
View File
@@ -0,0 +1,101 @@
'use strict';
const { EachLimit } = require('./eachLimit');
const { setLimit } = require('./internal/collection');
class PickByLimit extends EachLimit {
constructor(collection, limit, iterator) {
super(collection, limit, iterator, set);
this._result = {};
}
}
module.exports = { pickByLimit, PickByLimit };
function set(collection) {
setLimit.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (value) {
this._result[index] = this._coll[index];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
function callResolveObject(value, index) {
if (value) {
const key = this._keys[index];
this._result[key] = this._coll[key];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else if (this._callRest-- > 0) {
this._iterate();
}
}
/**
* `Aigle.pickByLimit` is almost the as [`Aigle.pickBy`](https://suguru03.github.io/aigle/docs/Aigle.html#pickBy) and
* [`Aigle.pickBySeries`](https://suguru03.github.io/aigle/docs/Aigle.html#pickBySeries), but it will work with concurrency.
* @param {Array|Object} collection
* @param {integer} [limit=8]
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = (num, index) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.pickByLimit(collection, 2, iterator)
* .then(object => {
* console.log(object); // { '0': 1, '1': 5, '2': 3 }
* console.log(order); // [1, 3, 5, 2, 4]
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 5, c: 3, d: 4, e: 2 };
* const iterator = (num, key) => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.pickByLimit(collection, 2, iterator)
* .then(object => {
* console.log(object); // { a: 1, b: 5, c: 3 }
* console.log(order); // [1, 3, 5, 2, 4]
* });
*
* @example
* const order = [];
* const collection = [1, 5, 3, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.pickByLimit(collection, iterator)
* .then(object => {
* console.log(object); // { '0': 1, '1': 5, '2': 3 }
* console.log(order); // [1, 2, 3, 4, 5]
* });
*/
function pickByLimit(collection, limit, iterator) {
return new PickByLimit(collection, limit, iterator)._execute();
}
+83
View File
@@ -0,0 +1,83 @@
'use strict';
const { EachSeries } = require('./eachSeries');
const { setSeries } = require('./internal/collection');
class PickBySeries extends EachSeries {
constructor(collection, iterator) {
super(collection, iterator, set);
this._result = {};
}
}
module.exports = { pickBySeries, PickBySeries };
function set(collection) {
setSeries.call(this, collection);
this._callResolve = this._keys === undefined ? callResolveArray : callResolveObject;
return this;
}
function callResolveArray(value, index) {
if (value) {
this._result[index] = this._coll[index];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
function callResolveObject(value, index) {
if (value) {
const key = this._keys[index];
this._result[key] = this._coll[key];
}
if (--this._rest === 0) {
this._promise._resolve(this._result);
} else {
this._iterate();
}
}
/**
* `Aigle.pickBySeries` is almost the as [`Aigle.pickBy`](https://suguru03.github.io/aigle/docs/Aigle.html#pickBy), but it will work in series.
* @param {Array|Object} collection
* @param {Function} iterator
* @return {Aigle} Returns an Aigle instance
* @example
* const order = [];
* const collection = [1, 4, 2];
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num % 2;
* });
* };
* Aigle.pickBySeries(collection, iterator)
* .then(object => {
* console.log(object); // { '0': 1 }
* console.log(order); // [1, 4, 2]
* });
*
* @example
* const order = [];
* const collection = { a: 1, b: 4, c: 2 };
* const iterator = num => {
* return Aigle.delay(num * 10)
* .then(() => {
* order.push(num);
* return num * 2;
* });
* };
* Aigle.pickBySeries(collection, iterator)
* .then(object => {
* console.log(object); // { a: 1 }
* console.log(order); // [1, 4, 2]
* });
*/
function pickBySeries(collection, iterator) {
return new PickBySeries(collection, iterator)._execute();
}

Some files were not shown because too many files have changed in this diff Show More