From 2ffc3d2b8f44696da25161e666960851df5fe6cd Mon Sep 17 00:00:00 2001 From: Travis CI Date: Fri, 22 Dec 2017 15:57:15 +0000 Subject: [PATCH] Travis build: 126 --- README.md | 46 +++++++++++++++++++++++----------------------- docs/index.html | 34 +++++++++++++++++----------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 8f122036a..d7b85ac23 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ ## Table of Contents ### Adapter +* [`promisify`](#promisify) * [`spreadOver`](#spreadover) ### Array @@ -83,7 +84,6 @@ * [`curry`](#curry) * [`functionName`](#functionname) * [`pipe`](#pipe) -* [`promisify`](#promisify) * [`runPromisesInSeries`](#runpromisesinseries) * [`sleep`](#sleep) @@ -167,6 +167,28 @@ ## Adapter +### promisify + +Converts an asynchronous function to return a promise. + +Use currying to return a function returning a `Promise` that calls the original function. +Use the `...rest` operator to pass in all the parameters. + +*In Node 8+, you can use [`util.promisify`](https://nodejs.org/api/util.html#util_util_promisify_original)* + +```js +const promisify = func => + (...args) => + new Promise((resolve, reject) => + func(...args, (err, result) => + err ? reject(err) : resolve(result)) + ); +// const delay = promisify((d, cb) => setTimeout(cb, d)) +// delay(2000).then(() => console.log('Hi!')) -> Promise resolves after 2s +``` + +[⬆ back to top](#table-of-contents) + ### spreadOver Takes a veriadic function and returns a closure that accepts an array of arguments to map to the inputs of the function. @@ -1135,28 +1157,6 @@ multiplyAndAdd5(5, 2) -> 15 [⬆ back to top](#table-of-contents) -### promisify - -Converts an asynchronous function to return a promise. - -Use currying to return a function returning a `Promise` that calls the original function. -Use the `...rest` operator to pass in all the parameters. - -*In Node 8+, you can use [`util.promisify`](https://nodejs.org/api/util.html#util_util_promisify_original)* - -```js -const promisify = func => - (...args) => - new Promise((resolve, reject) => - func(...args, (err, result) => - err ? reject(err) : resolve(result)) - ); -// const delay = promisify((d, cb) => setTimeout(cb, d)) -// delay(2000).then(() => console.log('Hi!')) -> Promise resolves after 2s -``` - -[⬆ back to top](#table-of-contents) - ### runPromisesInSeries Runs an array of promises in series. diff --git a/docs/index.html b/docs/index.html index 9ebc63021..551066214 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,8 @@

Adapter -

spreadOver +promisify +spreadOver

Array

arrayGcd @@ -111,7 +112,6 @@ curry functionName pipe -promisify runPromisesInSeries sleep @@ -194,7 +194,21 @@ flip
 

Adapter

-

spreadOver

+

promisify

+

Converts an asynchronous function to return a promise.

+

Use currying to return a function returning a Promise that calls the original function. +Use the ...rest operator to pass in all the parameters.

+

In Node 8+, you can use util.promisify

+
const promisify = func =>
+  (...args) =>
+    new Promise((resolve, reject) =>
+      func(...args, (err, result) =>
+        err ? reject(err) : resolve(result))
+    );
+// const delay = promisify((d, cb) => setTimeout(cb, d))
+// delay(2000).then(() => console.log('Hi!')) -> Promise resolves after 2s
+
+

spreadOver

Takes a veriadic function and returns a closure that accepts an array of arguments to map to the inputs of the function.

Use closures and the spread operator (...) to map the array of arguments to the inputs of the function.

const spreadOver = fn => argsArr => fn(...argsArr);
@@ -733,20 +747,6 @@ const multiplyAndAdd5 = pipeFunctions(multiply, add5)
 multiplyAndAdd5(5, 2) -> 15
 */
 
-

promisify

-

Converts an asynchronous function to return a promise.

-

Use currying to return a function returning a Promise that calls the original function. -Use the ...rest operator to pass in all the parameters.

-

In Node 8+, you can use util.promisify

-
const promisify = func =>
-  (...args) =>
-    new Promise((resolve, reject) =>
-      func(...args, (err, result) =>
-        err ? reject(err) : resolve(result))
-    );
-// const delay = promisify((d, cb) => setTimeout(cb, d))
-// delay(2000).then(() => console.log('Hi!')) -> Promise resolves after 2s
-

runPromisesInSeries

Runs an array of promises in series.

Use Array.reduce() to create a promise chain, where each promise returns the next promise when resolved.