JSPM

@stdlib/utils-thunk

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q16015F
  • License Apache-2.0

Generate a thunk.

Package Exports

  • @stdlib/utils-thunk
  • @stdlib/utils-thunk/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@stdlib/utils-thunk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

thunk

NPM version Build Status Coverage Status

Generate a thunk.

Installation

npm install @stdlib/utils-thunk

Usage

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

thunk( fcn[, ...args] )

Returns a thunk (i.e., an anonymous function having arity 0 and which invokes a provided function with specified arguments).

var add = require( '@stdlib/math-base-ops-add' );

var f = thunk( add, 2.0, 3.0 );
// returns <Function>

var v = f();
// returns 5

// ...

v = f();
// returns 5

Examples

var add = require( '@stdlib/math-base-ops-add' );
var decorateAfter = require( '@stdlib/utils-decorate-after' );
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory;
var thunk = require( '@stdlib/utils-thunk' );

function log( v ) {
    console.log( v );
}

// Create a PRNG for generating uniformly distributed pseudorandom integers:
var randi = discreteUniform( 100, 1000 );

// Randomly delay evaluation of various thunks...
var i;
for ( i = 0; i < 10; i++ ) {
    setTimeout( decorateAfter( thunk( add, i, i+1 ), 0, log ), randi() );
}

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 © 2016-2023. The Stdlib Authors.