UNPKG

764 BHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <title>functional-pipeline</title>
6 <script src="fp.js"></script>
7 </head>
8 <body>
9 <h1>functional-pipeline</h1>
10 <script>
11 (function (fp) {
12 if (typeof fp === 'undefined') {
13 throw new Error('Cannot find fp object');
14 }
15 console.log('Found fp object');
16 function triple(x) { return 3 * x; }
17 function add2(x) { return x + 2; }
18 var data = {
19 age: 10,
20 getAge: function () { return this.age; }
21 };
22 var pipeline = fp('getAge', triple, add2);
23 var result = pipeline(data);
24 if (result !== 32) {
25 throw new Error('invalid result ' + result);
26 }
27 }(window.fp));
28 </script>
29 </body>
30</html>