unarify

0.1.0 • Public • Published

Tandoori

Unarify is a function wrapper that returns a function, which when called with nothing, will with any arguments, will return an array of functions, where each function references one parameter of the original function

Installation:

 $ npm install unarify
Why use it?

It can be used to keep referece to the original function while passing the other ones around. For example, you can have multiple race conditions, and use this to only invoke the function when all the race conditions have been satisfied.

It also allows for lazy(ish) evaluation, by saving parameters until the function needs to be called. It's not quite lazy... but it's close.

Usage:

    const unarify = require('unarify');
    let add = (a, b) => a + b;
    let restful = (...rest) => rest;
    let unaryAdd = unarify(add);
    => [Function]
    let addFuncs = unaryAdd();
    => [ [Function], [Function] ]
    addFuncs[0](6);
    => 1 //Only 1 element is still not set
    addFuncs[1](7);
    => 0 //All elements are set
    unaryAdd();
    => 13 // 6 + 7
    unaryAdd(true)
    => [ [Function], [Function] ] //Returns the array of functions to set parameters even though
    //they've all been set. Equivalent to unaryAdd(false), unaryAdd(undefined), etc.
 
    //Does not work with rest parameters
    //Works with functions with mixed rest and normal
    //But only for the normal parameters.

Edits:

Github Repo to come soon

Package Sidebar

Install

npm i unarify

Weekly Downloads

4

Version

0.1.0

License

MIT

Last publish

Collaborators

  • tomzer0