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.2 KB
|
Line | |
---|
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 weave
|
---|
12 | * @memberOf RA
|
---|
13 | * @since {@link https://char0n.github.io/ramda-adjunct/1.7.0|v1.7.0}
|
---|
14 | * @category Function
|
---|
15 | * @sig (*... -> *) -> * -> (*... -> *)
|
---|
16 | * @param {Function} fn The function to weave
|
---|
17 | * @param {*} config The configuration to weave into fn
|
---|
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 | * // no weaving
|
---|
28 | * log('test').run(console); //=> prints 'test'
|
---|
29 | *
|
---|
30 | * // weaving
|
---|
31 | * const wlog = RA.weave(log, console);
|
---|
32 | * wlog('test'); //=> prints 'test'
|
---|
33 | */
|
---|
34 | var weave = (0, _ramda.curryN)(2, function (fn, config) {
|
---|
35 | return (0, _ramda.curryN)(fn.length, function () {
|
---|
36 | return fn.apply(void 0, arguments).run(config);
|
---|
37 | });
|
---|
38 | });
|
---|
39 | var _default = weave;
|
---|
40 | exports["default"] = _default; |
---|
Note:
See
TracBrowser
for help on using the repository browser.