From 2bee95ff1ce0aeb2178c4132a299b3693afdc2e3 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Wed, 31 Jan 2018 17:08:56 +0000 Subject: [PATCH] Travis build: 1498 --- README.md | 11 ++++------- docs/index.html | 11 ++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 0e1a736b2..be06e304c 100644 --- a/README.md +++ b/README.md @@ -574,13 +574,10 @@ const overArgs = (fn, transforms) => (...args) => fn(...args.map((val, i) => tra Examples ```js -var func = overArgs( - function(x, y) { - return [x, y]; - }, - [square, doubled] -); -func(9, 3); // [81, 6] +const square = n => n * n; +const double = n => n * 2; +const fn = overArgs((x, y) => [x, y], [square, double]); +fn(9, 3); // [81, 6] ``` diff --git a/docs/index.html b/docs/index.html index afd1efa7d..8fd7f7da2 100644 --- a/docs/index.html +++ b/docs/index.html @@ -79,13 +79,10 @@ Object.assig
const minMax = over(Math.min, Math.max);
 minMax(1, 2, 3, 4, 5); // [1,5]
 

overArgs

Creates a function that invokes the provided function with its arguments transformed.

Use Array.map() to apply transforms to args in combination with the spread operator (...) to pass the transformed arguments to fn.

const overArgs = (fn, transforms) => (...args) => fn(...args.map((val, i) => transforms[i](val)));
-
var func = overArgs(
-  function(x, y) {
-    return [x, y];
-  },
-  [square, doubled]
-);
-func(9, 3); // [81, 6]
+
const square = n => n * n;
+const double = n => n * 2;
+const fn = overArgs((x, y) => [x, y], [square, double]);
+fn(9, 3); // [81, 6]
 

pipeAsyncFunctions

Performs left-to-right function composition for asynchronous functions.

Use Array.reduce() with the spread operator (...) to perform left-to-right function composition using Promise.then(). The functions can return a combination of: simple values, Promise's, or they can be defined as async ones returning through await. All functions must be unary.

const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));
 
const sum = pipeAsyncFunctions(
   x => x + 1,