Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns a Promise which resolves with a value in form of a tuple.
- * @param promiseFn A Promise to resolve as a tuple.
- * @returns Promise A Promise which resolves to a tuple of [error, ...results]
- */
- export function tuple (promise) {
- return promise
- .then((...results) => [null, ...results])
- .catch(error => [error])
- }
- /**
- * Returns a function which creates a tuple-ful Promise.
- * @param fn A function to create a tuple from.
- * @returns A function which creates a tuple from `fn`.
- */
- export function tuplify (fn) {
- return function tupleFn (...args) {
- return tuple(fn(...args))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement