ramda-adjunct
Version:
Ramda Adjunct is the most popular and most comprehensive set of utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.
44 lines (41 loc) • 1.33 kB
JavaScript
exports.__esModule = true;
exports["default"] = void 0;
var _ramda = require("ramda");
/**
* Weaves a configuration into function returning the runnable monad like `Reader` or `Free`.
* This allows us to pre-bind the configuration in advance and use the weaved function
* without need to explicitly pass the configuration on every call.
*
* @func weaveLazy
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/1.10.0|v1.10.0}
* @category Function
* @sig (*... -> *) -> (* -> *) -> (*... -> *)
* @param {Function} fn The function to weave
* @param {Function} configAccessor The function that returns the configuration object
* @return {Function} Auto-curried weaved function
* @example
*
* const { Reader: reader } = require('monet');
*
* const log = value => reader(
* config => config.log(value)
* );
*
* const consoleAccessor = R.always(console);
*
* // no weaving
* log('test').run(console); //=> prints 'test'
*
* // weaving
* const wlog = RA.weaveLazy(log, consoleAccessor);
* wlog('test'); //=> prints 'test'
*/
var weaveLazy = (0, _ramda.curryN)(2, function (fn, configAccessor) {
return (0, _ramda.curryN)(fn.length, function () {
return fn.apply(void 0, arguments).run(configAccessor());
});
});
var _default = weaveLazy;
exports["default"] = _default;
;