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
Generate a thunk.
Installation
npm install @stdlib/utils-thunkUsage
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 5Examples
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
License
See LICENSE.
Copyright
Copyright © 2016-2023. The Stdlib Authors.