source: node_modules/ramda-adjunct/src/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.1 KB
Line 
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 weaveLazy
9 * @memberOf RA
10 * @since {@link https://char0n.github.io/ramda-adjunct/1.10.0|v1.10.0}
11 * @category Function
12 * @sig (*... -> *) -> (* -> *) -> (*... -> *)
13 * @param {Function} fn The function to weave
14 * @param {Function} configAccessor The function that returns the configuration object
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 * const consoleAccessor = R.always(console);
25 *
26 * // no weaving
27 * log('test').run(console); //=> prints 'test'
28 *
29 * // weaving
30 * const wlog = RA.weaveLazy(log, consoleAccessor);
31 * wlog('test'); //=> prints 'test'
32 */
33const weaveLazy = curryN(2, (fn, configAccessor) =>
34 curryN(fn.length, (...args) => fn(...args).run(configAccessor()))
35);
36
37export default weaveLazy;
Note: See TracBrowser for help on using the repository browser.