Curry a Function
Curry a Function is a reusable JavaScript snippet. Transforms a function with multiple arguments into a sequence of nested functions, each taking a single argument. The full implementation: function curry(fn) { return function curried(...args) { if (args.length >= fn.length) { return fn.apply(this, args) } return function(...more) { return curried.apply(this, args.concat(more)) } } } // Usage const add = (a, b, c) => a + b + c const curriedAdd = curry(add) curriedAdd(1)(2)(3) // 6 curriedAdd(1, 2)(3) // 6 // Practical example: logger const log = curry((level, msg) => console.log(`[${level.toUpperCase()}] ${msg}`)) const info = log('info') const warn = log('warn') info('System started') // [INFO] System started This snippet uses only standard JavaScript with no dependencies, so it runs in modern browsers and Node.js alike. Browse more patterns in the snippet library, or paste the code straight into the playground to experiment with it.