source: node_modules/ramda-adjunct/lib/weaveLazy.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _ramda = require("ramda");
6/**
7 * Weaves a configuration into function returning the runnable monad like `Reader` or `Free`.
8 * This allows us to pre-bind the configuration in advance and use the weaved function
9 * without need to explicitly pass the configuration on every call.
10 *
11 * @func weaveLazy
12 * @memberOf RA
13 * @since {@link https://char0n.github.io/ramda-adjunct/1.10.0|v1.10.0}
14 * @category Function
15 * @sig (*... -> *) -> (* -> *) -> (*... -> *)
16 * @param {Function} fn The function to weave
17 * @param {Function} configAccessor The function that returns the configuration object
18 * @return {Function} Auto-curried weaved function
19 * @example
20 *
21 * const { Reader: reader } = require('monet');
22 *
23 * const log = value => reader(
24 * config => config.log(value)
25 * );
26 *
27 * const consoleAccessor = R.always(console);
28 *
29 * // no weaving
30 * log('test').run(console); //=> prints 'test'
31 *
32 * // weaving
33 * const wlog = RA.weaveLazy(log, consoleAccessor);
34 * wlog('test'); //=> prints 'test'
35 */
36var weaveLazy = (0, _ramda.curryN)(2, function (fn, configAccessor) {
37 return (0, _ramda.curryN)(fn.length, function () {
38 return fn.apply(void 0, arguments).run(configAccessor());
39 });
40});
41var _default = weaveLazy;
42exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.