



Feature Complete Curry Library

- Fixed Functions ⟶ Curry
- Operators ⟶ Curry
- Curry ⟶ Fixed Functions
- Infinite Currying
- Lazy Curry
constcurry=require('omg-curry')
Convert a function into curry
functionmap(fn,default,list){}constmapK=curry.fixed(map)constsquare=a=>a**2mapK(square)(0)([1,2,3,4,null])// [1, 4, 9, 16, 0]// or reuseconstmapSquare=mapK(square)(0)mapSquare([1,2,3,4,null])// [1, 4, 9, 16, 0]
Create N-length Curry from an operator
constadd=(a,b)=>a+bconstadd4=curry.op(add,4)add4(1)(3)(5)(10)add4(1)(3,5)(10)add4(1,3,5,10)// 19constaddInfty=curry.op(add,Infinity)// () to endaddInfty(1)(1)(1,1)(1)(1)()// 6constadd4Lazy=curry.op(add,4,true)// same as add4 buts evaluates at the end
constaltSum=(a,b,i)=>a+(-1)**i*bconstaltSum5=curry.op(altSum,5)// (a, b, c, d, e) => a - b + c - d + ealtSum5(1)(2)(3)(4,5)// 1 - 2 + 3 - 4 + 5// 3
Convert Curry to Fixed Functions
constadd4Fixed=curry.deCurry(add4Curry)
A Curry takes arguments one by one unlike functions which take all arguments at once.
// Functionadd(1,2,3)// 6// Curryadd(1)(2)(3)// 6