1 | <!doctype html>
|
2 | <html>
|
3 |
|
4 | <head>
|
5 | <meta name="generator" content="JSDoc 3.6.2">
|
6 | <meta charset="utf-8">
|
7 | <title>keyu 2.0.0 » Source: fp/index.js</title>
|
8 | <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
|
9 | <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
|
10 | <link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
|
11 | <link href="css/baseline.css" rel="stylesheet">
|
12 | </head>
|
13 |
|
14 | <body onload="prettyPrint()">
|
15 | <nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
|
16 | <div id="jsdoc-navbar-container">
|
17 | <div id="jsdoc-navbar-content">
|
18 | <a href="index.html" class="jsdoc-navbar-package-name">keyu 2.<wbr>0.<wbr>0</a>
|
19 | </div>
|
20 | </div>
|
21 | </nav>
|
22 | <div id="jsdoc-body-container">
|
23 | <div id="jsdoc-content">
|
24 | <div id="jsdoc-content-container">
|
25 | <div id="jsdoc-banner" role="banner">
|
26 | </div>
|
27 | <div id="jsdoc-main" role="main">
|
28 | <header class="page-header">
|
29 | <h1>Source: fp/index.js</h1>
|
30 | </header>
|
31 | <article>
|
32 | <pre class="prettyprint linenums"><code>/** @module fp **/
|
33 |
|
34 | /** Reducer function used by `pipe` and `compose` functions to compose sync and async functions
|
35 | * @argument {function|Promise} chain a chain of functions or promises
|
36 | * @argument {function|Promise} func a new function or promise to add to the chain
|
37 | * @method
|
38 | */
|
39 | const mixCompose = (chain, func) => (chain instanceof Promise || typeof chain.then === 'function' ? chain.then(func) : func(chain));
|
40 |
|
41 | /** Compose regular functions or promises generating a final function.
|
42 | * - Compose works from left to right.
|
43 | * - If you compose one single promise the final result will be a promise too.
|
44 | * - You can only compose functions with the same arity.
|
45 | * @argument {function|Promise} arguments N number of functions or promises.
|
46 | * @returns {function|Promise} function or Promise that execute the all composed ones.
|
47 | * @example
|
48 | * const sum3 = a => a+3
|
49 | * const mult2 = a => a*2
|
50 | * const sum2Async = a => Promise.resolve(a+2) // Simulate async response
|
51 | *
|
52 | * const sumAndMult = pipe(sum3,mult2);
|
53 | * sumAndMult(1) // -> (1+3)*2 = 8
|
54 | *
|
55 | * const sumAndMultAsync = pipe(sum3,mult2,sum2Async);
|
56 | * await sumAndMultAsync(1) // -> ((1+3)*2)+2 = 10
|
57 | * @method
|
58 | */
|
59 | const pipe = (...fn) => input => fn.reduce(mixCompose, input);
|
60 |
|
61 | /** Compose regular functions or promises generating a final function.
|
62 | * - Compose works from right to left.
|
63 | * - If you compose one single promise the final result will be a promise too.
|
64 | * - You can only compose functions with the same arity.
|
65 | * @argument {function|Promise} arguments N number of functions or promises.
|
66 | * @returns {function|Promise} function or Promise that execute the all composed ones.
|
67 | * @example
|
68 | * const sum3 = a => a+3
|
69 | * const mult2 = a => a*2
|
70 | * const sum2Async = a => Promise.resolve(a+2) // Simulate async response
|
71 | *
|
72 | * const sumAndMult = compose(sum3,mult2);
|
73 | * sumAndMult(1) // -> (1*2)+3 = 5
|
74 | *
|
75 | * const sumAndMultAsync = compose(sum3,mult2,sum2Async);
|
76 | * await sumAndMultAsync(1) // -> ((1+2)*2)+3 = 9
|
77 | * @method
|
78 | */
|
79 | const compose = (...fn) => input => fn.reduceRight(mixCompose, input);
|
80 |
|
81 | /** Currify any function allowing the partial application of its arguments
|
82 | * @argument {function} function function with at least two arguments
|
83 | * @returns {function} curried function.
|
84 | * @example
|
85 | * const sum = curry((a,b) = a+b);
|
86 | * const sum3 = sum(3);
|
87 | * sum3(3) // -> 6
|
88 | * sum(3,3) // -> 6
|
89 | * sum(3)(3) // -> 6
|
90 | * @method
|
91 | */
|
92 | const curry = f => {
|
93 | if (typeof f !== 'function') {
|
94 | throw new Error(`curry requires a function, [${typeof f}] passed`);
|
95 | }
|
96 | return function currify(...arg) {
|
97 | const args = Array.prototype.slice.call(arg);
|
98 | return args.length >= f.length ? f(...args) : currify.bind(null, ...args);
|
99 | };
|
100 | };
|
101 | module.exports = { pipe, compose, curry };
|
102 | </code></pre>
|
103 | </article>
|
104 | </div>
|
105 | </div>
|
106 | <nav id="jsdoc-toc-nav" role="navigation"></nav>
|
107 | </div>
|
108 | </div>
|
109 | <footer id="jsdoc-footer" class="jsdoc-footer">
|
110 | <div id="jsdoc-footer-container">
|
111 | <p>
|
112 | Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.2 on June 17, 2019.
|
113 | </p>
|
114 | </div>
|
115 | </footer>
|
116 | <script src="scripts/jquery.min.js"></script>
|
117 | <script src="scripts/jquery.cookie.js"></script>
|
118 | <script src="scripts/tree.jquery.js"></script>
|
119 | <script src="scripts/prettify.js"></script>
|
120 | <script src="scripts/jsdoc-toc.js"></script>
|
121 | <script src="scripts/linenumber.js"></script>
|
122 | <script src="scripts/scrollanchor.js"></script>
|
123 | </body>
|
124 |
|
125 | </html> |
\ | No newline at end of file |