Skip to content

Instantly share code, notes, and snippets.

@henrik1
Last active June 8, 2022 22:11
Show Gist options
  • Save henrik1/30909221e1eb58070bfc944167853ed2 to your computer and use it in GitHub Desktop.
Save henrik1/30909221e1eb58070bfc944167853ed2 to your computer and use it in GitHub Desktop.
Curry example
// 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
@igruenig
Copy link

  1. There is a typo on line 3: amout should be amount
  2. On line 14 I believe the second argument should be 0 instead of 10 to make it a free transaction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment