Skip to content

Commit cf9b7ae

Browse files
committed
Improve partial examples
1 parent 13dbaaf commit cf9b7ae

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

JavaScript/4-partial.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ const f12 = partial(f11, 2);
1111
const f13 = partial(f12, 3);
1212
const y1 = f13(4);
1313
console.log(y1);
14+
15+
const f21 = partial(sum4, 1, 2);
16+
const f22 = partial(f21, 3);
17+
const y2 = f22(4);
18+
console.log(y2);

JavaScript/5-partial-ext.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
const partial = (fn, ...args) => (...rest) => fn(...args.concat(rest));
4+
5+
// Usage
6+
7+
const sum4 = (a, b, c, d) => (a + b + c + d);
8+
9+
const f11 = partial(sum4, 1);
10+
const f12 = partial(f11, 2);
11+
const f13 = partial(f12, 3);
12+
const y1 = f13(4);
13+
console.log(y1);
14+
15+
const f21 = partial(sum4, 1, 2);
16+
const f22 = partial(f21, 3);
17+
const y2 = f22(4);
18+
console.log(y2);

0 commit comments

Comments
 (0)