CLOVIS
03/30/2020, 3:54 PMcurry()
which can be used like this:
val twice = { a: Int, b: Int -> a * b }.curry()(2)
I would be interested in the following form (more readable in my opinion):
val twice = { a: Int, b: Int -> a * b }.curry (2)
Where curry
would be a function which takes a number of arguments and creates another function with the leftover arguments:
val e = { a: Int, b: Int, c: Int, d: Int -> a * b * c * d }.curry(2, 2)
// val e: (Int, Int) -> Int
What do you think?raulraja
03/30/2020, 4:37 PMraulraja
03/30/2020, 4:38 PMval <P1, P2, R> ((P1, P2) -> R).curried: (P1) -> (P2) -> R
get() = { p1: P1 -> { p2: P2 -> this(p1, p2) } }
val twice: (Int) -> Int = { a: Int, b: Int -> a * b }.curried(2)
CLOVIS
04/02/2020, 7:29 PMfun thing(a: Int, b: Int, c: Int, d: Int): Int
val other = thing.curry(b = 3, d = 2)(5, 6)
(The language doesn't allow that AFAIK so it might need to go through a compiler plugin?)
I haven't used curry in Kotlin yet, but in Racket a common issue is that currification is only useful if the function is defined with the parameters in the right order. I've heard (but I'm unsure) that the convention in Scala is to put the collection as the last parameter so it's possible to curry over the first one and then map over the resulting function; but in Kotlin the convention is to end with a lambda and to put the collection as a receiver, which doesn't sound convenient at all for currification if the order of arguments is respected...
Does Arrow have a solution to this problem?