Last active
June 8, 2022 22:11
-
-
Save henrik1/30909221e1eb58070bfc944167853ed2 to your computer and use it in GitHub Desktop.
Curry example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// consider the following function to process bank transaction | |
const transaction = (fee, balance, amount) => ( | |
balance + amout - fee; | |
); | |
// Simple curry implementation | |
const curry = (fn, ...args) => ( | |
(..._arg) => ( | |
fn(...args, ..._arg) | |
) | |
); | |
// We could easily reuse the transaction logic for a "free" transaction | |
const freeTransaction = curry(transaction, 0); | |
freeTransaction(10, 90); // = 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
amout
should beamount