1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports["default"] = void 0;
|
---|
5 | var _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 | */
|
---|
36 | var 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 | });
|
---|
41 | var _default = weaveLazy;
|
---|
42 | exports["default"] = _default; |
---|