entrust v0.0.21
Delegatee-last curried functions for great justice
You can use entrust to easily transform methods into a curried, delegatee-last (data-last) form. If you are used to functional programming (FP) paradigms, this makes FP in JS much easier.
Example:
// native map looks like: array.map(fn)
// entrust map looks like: e1(`map`, fn, array)
import {e1} from 'entrust'
const map = e1(`map`) // this takes a function first, and then the data
map(x => x * 2, [1,2,3]) // [2,4,6]Here's an example of how to apply the same approach to a tertiary function, like reduce:
import {e2} from 'entrust'
// native reduce looks like: array.reduce(fn, initial)
const reduce = e2(`reduce`) // e2(`reduce`, fn, initial, array)
const sum = reduce((a, b) => a + b, 0)
sum([1,2,3]) // 6
sum([1,2,3,4]) // 10
sum([1,2,3,4,5]) // 15NB: This approach is used extensively in the f-utility module. You may want to take a look at it here.
entrust is built using katsu-curry's curry implementation. However, if you would like to use a different curry implementation, this is easily accomplished using the custom API. This specific technque is used to generate entrust's "debug-mode" export: entrust/debug.js.
API
Table of Contents
custom
generate a customized version of entrust's API
Parameters
curryfunction a function which curries
Examples
import {custom} from 'entrust'
import curry from 'lodash/fp/curry'
const {e0} = custom(curry)Returns object raw+ an augmented version of the raw API
eN
invoke a delegated method with arguments as an array. enforces specific arity
Parameters
nnumber 0 - 10methodstring a function name on your delegateeargsArray arguments to pass to your delegatee's methoddelegateeany something with methods
Examples
import {eN} from 'entrust'
eN(0, `toUpperCase`, [], `cool`) // `COOL`
eN(1, `map`, [(x) => x * 2], [1,2,3]) // [2,4,6]
eN(2, `reduce`, [(a, b) => (a + b), 0], [1,2,3]) // 6Returns any the result of delegating to the method with some arguments
eD
invoke a delegated method with arguments as an array. enforces specific arity Yells at you if you give arguments that don't match the expected arity.
Parameters
nnumber 0 - 10methodstring a function name on your delegateeargsArray arguments to pass to your delegatee's methoddelegateeany something with methods
Examples
import {eD} from 'entrust'
eD(0, `toUpperCase`, [], `cool`) // `COOL`
eD(1, `map`, [(x) => x * 2], [1,2,3]) // [2,4,6]
eD(2, `reduce`, [(a, b) => (a + b), 0], [1,2,3]) // 6
eD(2, `reduce`, [(a, b) => (a + b)], [1, 2, 3]) // throws errorReturns any the result of delegating to the method with some arguments
e0
Parameters
Examples
import {e0} from 'entrust'
const toLowerCase = e0(`toLowerCase`)
toLowerCase(`COOL`) // coolReturns any
e1
Parameters
Examples
import {e1} from 'entrust'
const split = e1(`split`)
split(`:`, `c:o:o:l`) // [`c`,`o`,`o`,`l`]Returns any
e10
Parameters
fnstring a function nameaany some parameterbany some parametercany some parameterdany some parametereany some parameterfany some parametergany some parameterhany some parameteriany some parameterjany some parameterxObject an object
Returns any
e2
Parameters
Examples
import {e2} from 'entrust'
const replace = e2(`replace`)
replace(`old`, `new`, `oldnew`) // newnewReturns any
e3
Parameters
fnstring a function nameaany some parameterbany some parametercany some parameterxObject an object
Returns any
e4
Parameters
fnstring a function nameaany some parameterbany some parametercany some parameterdany some parameterxObject an object
Returns any
e5
Parameters
fnstring a function nameaany some parameterbany some parametercany some parameterdany some parametereany some parameterxObject an object
Returns any
e6
Parameters
fnstring a function nameaany some parameterbany some parametercany some parameterdany some parametereany some parameterfany some parameterxObject an object
Returns any
e7
Parameters
fnstring a function nameaany some parameterbany some parametercany some parameterdany some parametereany some parameterfany some parametergany some parameterxObject an object
Returns any
e8
Parameters
fnstring a function nameaany some parameterbany some parametercany some parameterdany some parametereany some parameterfany some parametergany some parameterhany some parameterxObject an object
Returns any
e9
Parameters
fnstring a function nameaany some parameterbany some parametercany some parameterdany some parametereany some parameterfany some parametergany some parameterhany some parameteriany some parameterxObject an object
Returns any
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago