-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpartial-application.js
23 lines (19 loc) · 1020 Bytes
/
partial-application.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Partial Application
// Whenever a curried function has some, but not all of it's data
const getTaxForItems = tax => price => qty => {
const multiplied = price * qty;
return (tax * multiplied) + multiplied;
}
// Set state Tax Curry
// These become immutable versions of the tax
const taxTheFloridaItems = getTaxForItems(.07); // Set 't' tax to 7%
const taxTheCaliforniaItems = getTaxForItems(.90); // Set 't' tax to 90%
// Set state calculation for total pure function
//Set 'x' price to $9 for Florida and $20 for California;
// These become immutable versions of the tax with the price
const floridaPriceWithTax = taxTheFloridaItems(9);
const californiaPriceWithTax = taxTheCaliforniaItems(20);
console.log(floridaPriceWithTax(10)); // $96.3 | (10 * $9) + (10 * 9 * .07)
console.log(californiaPriceWithTax(10)); // $380 | (10 * $20) + (10 * $20 * .07)
console.log(floridaPriceWithTax(5)); // $48.15 | (5 * $9) + (5 * $9 *.07)
console.log(californiaPriceWithTax(5)); // $190 | (5 * $20) + (5 * $20 *.07)