@stdlib/utils-uncurry
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.7 • Public • Published

    uncurry

    NPM version Build Status Coverage Status dependencies

    Transform a curried function into a function invoked with multiple arguments.

    Installation

    npm install @stdlib/utils-uncurry

    Usage

    var uncurry = require( '@stdlib/utils-uncurry' );

    uncurry( fcn[, arity][, thisArg] )

    Transforms a curried function into a function invoked with multiple arguments.

    function add( x ) {
        return function add( y ) {
            return x + y;
        };
    }
    
    var fcn = uncurry( add );
    
    var sum = fcn( 2, 3 );
    // returns 5

    To enforce a fixed number of parameters, provide an arity argument.

    function add( x ) {
        return function add( y ) {
            return x + y;
        };
    }
    
    var fcn = uncurry( add, 2 );
    
    var sum = fcn( 9 );
    // throws <Error>

    To specify an execution context, provide a thisArg argument.

    function addX( x ) {
        this.x = x;
        return addY;
    }
    
    function addY( y ) {
        return this.x + y;
    }
    
    var fcn = uncurry( addX, {} );
    
    var sum = fcn( 2, 3 );
    // returns 5

    The function supports providing both an arity and execution context.

    function addX( x ) {
        this.x = x;
        return addY;
    }
    
    function addY( y ) {
        return this.x + y;
    }
    
    var fcn = uncurry( addX, 2, {} );
    
    var sum = fcn( 2, 3 );
    // returns 5
    
    sum = fcn( 4 );
    // throws <Error>

    Examples

    var curry = require( '@stdlib/utils-curry' );
    var uncurry = require( '@stdlib/utils-uncurry' );
    
    var uncurried;
    var curried;
    var bool;
    var out;
    var i;
    
    function add( x, y, z, w, t, s ) {
        return x + y + z + w + t + s;
    }
    
    out = add( 0, 10, 20, 30, 40, 50 );
    // returns 150
    
    // Transform `add` into a curried function:
    curried = curry( add );
    out = curried;
    for ( i = 0; i < add.length; i++ ) {
        out = out( i*10 );
    }
    bool = ( out === 150 );
    // returns true
    
    // Uncurry a curried function:
    uncurried = uncurry( curried );
    
    out = uncurried( 0, 10, 20, 30, 40, 50 );
    // returns 150

    Notice

    This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

    For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

    Community

    Chat


    License

    See LICENSE.

    Copyright

    Copyright © 2016-2021. The Stdlib Authors.

    Install

    npm i @stdlib/utils-uncurry

    Homepage

    stdlib.io

    DownloadsWeekly Downloads

    15

    Version

    0.0.7

    License

    Apache-2.0

    Unpacked Size

    41 kB

    Total Files

    9

    Last publish

    Collaborators

    • stdlib-bot
    • kgryte
    • planeshifter
    • rreusser