From 3f1fd80eb6e4ac5c15f35f12b00bebd7f3149dda Mon Sep 17 00:00:00 2001 From: Travis CI Date: Fri, 22 Dec 2017 19:56:52 +0000 Subject: [PATCH] Travis build: 157 --- README.md | 18 ++++++++++++++++++ docs/index.html | 15 +++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87b398a76..95a5000fd 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ ## Table of Contents ### Adapter +* [`call`](#call) * [`collectInto`](#collectinto) * [`flip`](#flip) * [`promisify`](#promisify) @@ -166,6 +167,23 @@ ## Adapter +### call + +Given a key and a set of arguments, call them when given a context. Primarily useful in composition. + +Use a closure to call a stored key with stored arguments. + +```js +const call = ( key, ...args ) => context => context[ key ]( ...args ); +/* +Promise.resolve( [ 1, 2, 3 ] ).then( call('map', x => 2 * x ) ).then( console.log ) //[ 2, 4, 6 ] +const map = call.bind(null, 'map') +Promise.resolve( [ 1, 2, 3 ] ).then( map( x => 2 * x ) ).then( console.log ) //[ 2, 4, 6 ] +*/ +``` + +[⬆ back to top](#table-of-contents) + ### collectInto Changes a function that accepts an array into a variadic function. diff --git a/docs/index.html b/docs/index.html index f4818317f..53d9a58c8 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,7 +42,8 @@

Adapter -

collectInto +call +collectInto flip promisify spreadOver @@ -193,7 +194,17 @@ validateNumber
 

Adapter

-

collectInto

+

call

+

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

+

Use a closure to call a stored key with stored arguments.

+
const call = ( key, ...args ) => context => context[ key ]( ...args );
+/*
+Promise.resolve( [ 1, 2, 3 ] ).then( call('map', x => 2 * x ) ).then( console.log ) //[ 2, 4, 6 ]
+const map = call.bind(null, 'map')
+Promise.resolve( [ 1, 2, 3 ] ).then( map( x => 2 * x ) ).then( console.log ) //[ 2, 4, 6 ]
+*/
+
+

collectInto

Changes a function that accepts an array into a variadic function.

Given a function, return a closure that collects all inputs into an array-accepting function.

const collectInto = fn => ( ...args ) => fn( args );