-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathpartial_application.js
More file actions
21 lines (16 loc) · 680 Bytes
/
Copy pathpartial_application.js
File metadata and controls
21 lines (16 loc) · 680 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
Partial application is a way to turn a function that expects multiple parameters
into one that will keep returning a new function until it receives all its arguments
"partially apply" some of the arguments now, filling in the rest later.
Partial application allows us to partially apply certain argument to create
new functions out of existing ones.
*/
const calculateTotal = (amount) => {
return (amount * 1.08) + 10;
}
const R = require('ramda');
const applyTaxOfEightPercent = R.partial(applyTax, [0.08]);
applyTaxOfEightPercent(100); // 108
applyTaxOfEightPercent(200); // 216
applyTaxOfEightPercent(190); // 205.2
applyTaxOfEightPercent(10000); // 10800