From what I can see in the documentation, Arrow ha...
# arrow
c
From what I can see in the documentation, Arrow has
curry()
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:
Copy code
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?
r
I think a better approach which would avoid so much wrapping would be to turn the existing functions into properties
Copy code
val <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)
c
Also, is there anyway to have currification that doesn't follow the same order of parameters? Something like
fun 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?