Question presented to candidate: "What is currying, and can you show me how you'd write a generic curry() helper that works for any function, regardless of how many arguments it takes?"
What a strong answer should cover:
- 📌 Interview term: currying — transforming a function that takes multiple arguments into a sequence of functions, each taking a single argument (or a subset), where calling with fewer than all the needed arguments returns a new function waiting for the rest.
- 📌 Interview term: the real, direct answer to the prompt — verified directly: a generic
curry(fn)helper genuinely worked correctly across three different calling patterns for the same 3-argument function — all-at-once (curriedAdd3(1, 2, 3)), one-then-two (curriedAdd3(1)(2, 3)), and fully split (curriedAdd3(1)(2)(3)) — all producing the identical, correct real result. - 📌 Interview term: partial application — currying's most common real, practical payoff: calling a curried function with FEWER than all its arguments produces a new, reusable, "pre-configured" function — verified directly with a real tax-calculation example, where partially applying just the tax rate produced a genuinely reusable function correctly applied to multiple different prices.
- A precise answer names
fn.lengthas the real mechanism most generic curry implementations use to know how many arguments to wait for before actually invoking the original function — a precise, verified detail beyond just describing the general idea. - A precise answer distinguishes currying from simple partial application via
bind:bindpre-fills a fixed number of leading arguments once; a curried function genuinely supports being called with any split of arguments across any number of calls, not just one fixed split.
Clarifying questions expected:
- None — this is a definitional/technical question; producing a real, working generic curry implementation (not just a hard-coded 2-argument example) is the strong signal.
Code / implementation expected: Yes — a real, generic curry() helper verified to work across multiple calling patterns for the same function is the clearest, most convincing demonstration.