fun
fun copied to clipboard
Add `curry` and `uncurry`
Add curry and uncurry functions. I’m not sure they’re particularly useful to be honest but given the confusion between currying and partial application in the R community it would have a nice educational effect to contrast the two operations of currying and partial function application.
Semantics (WLOG):
-
curry(f)returns a function that’s a curried version off. -
uncurry(g)returns a function that’s an uncurried version ofg. -
length(args(curry(f))) == 1. -
identical(uncurry(curry(f)), f).
Point (4) in particular might require some gymnastics if f is a closure — although strict identity is probably not required as long as the observable effect is identical.
Something to think about: currying a function with an ellipsis presumably yields an infinitely recursive function. Not clear how to resolve this, maybe just forbid it.