Never Perfectly Managed

    entrust

    0.0.21 • Public • Published

    entrust

    Delegatee-last curried functions for great justice

    Greenkeeper badge

    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]) // 15

    NB: 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

    • curry function 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

    • n number 0 - 10
    • method string a function name on your delegatee
    • args Array arguments to pass to your delegatee's method
    • delegatee any 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) => (+ b), 0], [1,2,3]) // 6

    Returns 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

    • n number 0 - 10
    • method string a function name on your delegatee
    • args Array arguments to pass to your delegatee's method
    • delegatee any 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) => (+ b), 0], [1,2,3]) // 6
    eD(2, `reduce`, [(a, b) => (+ b)], [1, 2, 3]) // throws error

    Returns any the result of delegating to the method with some arguments

    e0

    Parameters

    Examples

    import {e0} from 'entrust'
    const toLowerCase = e0(`toLowerCase`)
    toLowerCase(`COOL`) // cool

    Returns any

    e1

    Parameters

    • fn string a function name
    • a any some parameter
    • x Object an object

    Examples

    import {e1} from 'entrust'
    const split = e1(`split`)
    split(`:`, `c:o:o:l`) // [`c`,`o`,`o`,`l`]

    Returns any

    e10

    Parameters

    • fn string a function name
    • a any some parameter
    • b any some parameter
    • c any some parameter
    • d any some parameter
    • e any some parameter
    • f any some parameter
    • g any some parameter
    • h any some parameter
    • i any some parameter
    • j any some parameter
    • x Object an object

    Returns any

    e2

    Parameters

    • fn string a function name
    • a any some parameter
    • b any some parameter
    • x Object an object

    Examples

    import {e2} from 'entrust'
    const replace = e2(`replace`)
    replace(`old`, `new`, `oldnew`) // newnew

    Returns any

    e3

    Parameters

    • fn string a function name
    • a any some parameter
    • b any some parameter
    • c any some parameter
    • x Object an object

    Returns any

    e4

    Parameters

    • fn string a function name
    • a any some parameter
    • b any some parameter
    • c any some parameter
    • d any some parameter
    • x Object an object

    Returns any

    e5

    Parameters

    • fn string a function name
    • a any some parameter
    • b any some parameter
    • c any some parameter
    • d any some parameter
    • e any some parameter
    • x Object an object

    Returns any

    e6

    Parameters

    • fn string a function name
    • a any some parameter
    • b any some parameter
    • c any some parameter
    • d any some parameter
    • e any some parameter
    • f any some parameter
    • x Object an object

    Returns any

    e7

    Parameters

    • fn string a function name
    • a any some parameter
    • b any some parameter
    • c any some parameter
    • d any some parameter
    • e any some parameter
    • f any some parameter
    • g any some parameter
    • x Object an object

    Returns any

    e8

    Parameters

    • fn string a function name
    • a any some parameter
    • b any some parameter
    • c any some parameter
    • d any some parameter
    • e any some parameter
    • f any some parameter
    • g any some parameter
    • h any some parameter
    • x Object an object

    Returns any

    e9

    Parameters

    • fn string a function name
    • a any some parameter
    • b any some parameter
    • c any some parameter
    • d any some parameter
    • e any some parameter
    • f any some parameter
    • g any some parameter
    • h any some parameter
    • i any some parameter
    • x Object an object

    Returns any

    Install

    npm i entrust

    DownloadsWeekly Downloads

    104

    Version

    0.0.21

    License

    ISC

    Unpacked Size

    125 kB

    Total Files

    39

    Last publish

    Collaborators

    • brekk