Skip to content

Instantly share code, notes, and snippets.

@fumokmm
Created October 10, 2010 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fumokmm/619285 to your computer and use it in GitHub Desktop.
Save fumokmm/619285 to your computer and use it in GitHub Desktop.
// #g100pon No.68 curry/rcurry/ncurry
def func = { a, b, c, d -> (a + b) / (c - d) }
assert func(10, 20, 50, 35) == 2 // => (10 + 20) / (50 - 35)
// curry
def curriedFunc = func.curry(10)
assert curriedFunc(20, 50, 35) == 2 // => apply to b, c, and d.
// rcurry
def rightCurriedFunc = func.rcurry(50, 35)
assert rightCurriedFunc(10, 20) == 2 // => apply to a and b.
// ncurry
def indexCurriedFunc = func.ncurry(1, 20, 50)
assert indexCurriedFunc(10, 35) == 2 // => apply to a and d.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment