Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
83 changed files
with
1,009 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import tryFn from './tryFn'; | ||
import promised from './promised'; | ||
|
||
export default function concat(collection, iteratee) { | ||
export default promised(function concat(collection, iteratee) { | ||
return Promise.all(collection.map((...args) => tryFn(iteratee, ...args))) | ||
.then((results) => results.reduce((result, item) => result.concat(item), [])); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import tryFn from './tryFn'; | ||
import promised from './promised'; | ||
|
||
export default function concatSeries(collection, iteratee) { | ||
export default promised(function concatSeries(collection, iteratee) { | ||
return collection.reduce( | ||
(promise, item, index, collection) => promise.then((results) => { | ||
return tryFn(iteratee, item, index, collection) | ||
.then((result) => results.concat(result)); | ||
}), | ||
Promise.resolve([]) | ||
); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import tryFn from './tryFn'; | ||
import promised from './promised'; | ||
import until from './until'; | ||
|
||
export default function doUntil(task, condition, ...args) { | ||
export default promised(function doUntil(task, condition, ...args) { | ||
return tryFn(task, ...args) | ||
.then((result) => | ||
Array.isArray(result) | ||
? until(condition, task, ...result) | ||
: until(condition, task, result) | ||
); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import tryFn from './tryFn'; | ||
import promised from './promised'; | ||
import whilst from './whilst'; | ||
|
||
export default function doWhilst(task, condition, ...args) { | ||
export default promised(function doWhilst(task, condition, ...args) { | ||
return tryFn(task, ...args) | ||
.then((result) => | ||
Array.isArray(result) | ||
? whilst(condition, task, ...result) | ||
: whilst(condition, task, result) | ||
); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import tryFn from './tryFn'; | ||
import promised from './promised'; | ||
|
||
export default function each(collection, iteratee) { | ||
export default promised(function each(collection, iteratee) { | ||
return Promise.all(collection.map((...args) => tryFn(iteratee, ...args))); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import throat from 'throat'; | ||
import promised from './promised'; | ||
|
||
export default function eachLimit(collection, limit, iteratee) { | ||
export default promised(function eachLimit(collection, limit, iteratee) { | ||
if (! limit > 0) { | ||
return Promise.reject(new Error('Limit must be a number greater than 0.')); | ||
} | ||
|
||
return Promise.all(collection.map(throat(limit, iteratee))); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import tryFn from './tryFn'; | ||
import promised from './promised'; | ||
|
||
const ASYNCP_UNDEFINED = '__ASYNCP_UNDEFINED__'; | ||
|
||
export default function filter(collection, predicate) { | ||
export default promised(function filter(collection, predicate) { | ||
return Promise.all( | ||
collection.map((item, index, collection) => | ||
tryFn(predicate, item, index, collection) | ||
.then(result => result === true ? item : ASYNCP_UNDEFINED) | ||
) | ||
) | ||
.then(results => results.filter(item => item != ASYNCP_UNDEFINED)); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import tryFn from './tryFn'; | ||
import promised from './promised'; | ||
|
||
export default function forever(task, ...args) { | ||
export default promised(function forever(task, ...args) { | ||
return tryFn(task, ...args).then((result) => | ||
Array.isArray(result) | ||
? forever(task, ...result) | ||
: forever(task, result) | ||
); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import tryFn from './tryFn'; | ||
import promised from './promised'; | ||
|
||
export default function parallel(tasks, ...args) { | ||
export default promised(function parallel(tasks, ...args) { | ||
return Promise.all(tasks.map((task) => tryFn(task, ...args))); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import throat from 'throat'; | ||
import tryFn from './tryFn'; | ||
import promised from './promised'; | ||
|
||
export default function parallelLimit(tasks, limit, ...args) { | ||
export default promised(function parallelLimit(tasks, limit, ...args) { | ||
if (! limit > 0) { | ||
return Promise.reject(new Error('Limit must be a number greater than 0.')); | ||
} | ||
|
||
return Promise.all(tasks.map(throat(limit, (task) => tryFn(task, ...args)))); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default function promised(fn) { | ||
return function(...args) { | ||
return Promise.all(args) | ||
.then(args => fn.call(this, ...args)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import tryFn from './tryFn'; | ||
import promised from './promised'; | ||
|
||
export default function reduce(collection, result, iteratee) { | ||
export default promised(function reduce(collection, result, iteratee) { | ||
return collection.reduce( | ||
(promise, item, index, collection) => { | ||
return promise.then((result) => tryFn(iteratee, result, item, index, collection)); | ||
}, | ||
Promise.resolve(result) | ||
); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import tryFn from './tryFn'; | ||
import promised from './promised'; | ||
|
||
export default function reduceRight(collection, result, iteratee) { | ||
export default promised(function reduceRight(collection, result, iteratee) { | ||
return collection.reduceRight( | ||
(promise, item, index, collection) => { | ||
return promise.then((result) => tryFn(iteratee, result, item, index, collection)); | ||
}, | ||
Promise.resolve(result) | ||
); | ||
}; | ||
}); |
Oops, something went wrong.