source: node_modules/ramda-adjunct/src/weave.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.0 KB
RevLine 
[d24f17c]1import { curryN } from 'ramda';
2
3/**
4 * Weaves a configuration into function returning the runnable monad like `Reader` or `Free`.
5 * This allows us to pre-bind the configuration in advance and use the weaved function
6 * without need to explicitly pass the configuration on every call.
7 *
8 * @func weave
9 * @memberOf RA
10 * @since {@link https://char0n.github.io/ramda-adjunct/1.7.0|v1.7.0}
11 * @category Function
12 * @sig (*... -> *) -> * -> (*... -> *)
13 * @param {Function} fn The function to weave
14 * @param {*} config The configuration to weave into fn
15 * @return {Function} Auto-curried weaved function
16 * @example
17 *
18 * const { Reader: reader } = require('monet');
19 *
20 * const log = value => reader(
21 * config => config.log(value)
22 * );
23 *
24 * // no weaving
25 * log('test').run(console); //=> prints 'test'
26 *
27 * // weaving
28 * const wlog = RA.weave(log, console);
29 * wlog('test'); //=> prints 'test'
30 */
31const weave = curryN(2, (fn, config) =>
32 curryN(fn.length, (...args) => fn(...args).run(config))
33);
34
35export default weave;
Note: See TracBrowser for help on using the repository browser.