Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. /**
  2. * Returns a Promise which resolves with a value in form of a tuple.
  3. * @param promiseFn A Promise to resolve as a tuple.
  4. * @returns Promise A Promise which resolves to a tuple of [error, ...results]
  5. */
  6. export function tuple (promise) {
  7. return promise
  8. .then((...results) => [null, ...results])
  9. .catch(error => [error])
  10. }
  11.  
  12. /**
  13. * Returns a function which creates a tuple-ful Promise.
  14. * @param fn A function to create a tuple from.
  15. * @returns A function which creates a tuple from `fn`.
  16. */
  17. export function tuplify (fn) {
  18. return function tupleFn (...args) {
  19. return tuple(fn(...args))
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement