/* * Currying * The idea is to create a temp function that holds some * params of another func constant, thereby simplifying calls * * @author gtowell * Created: Aug 5, 2021 */ // a function with 4 params fun abcd(a:Int, b:Int, c:Int, d:Int) : Int { return (a+b+c)/d } // The currying function. This fixes 3 of the params // and retuns a new function with only the remaining param fun currier(a:Int, b:Int, c:Int) : (Int)->Int { return { d:Int -> abcd(a,b,c,d) } } fun main() { // the curried functions do not interact. Their closures are independent. val funcc = currier(10,20,30) val funcd = currier(5, 50, 150) println(funcc(3)) println(funcc(4)) println(funcd(10)) println(funcc(10)) }