mc
12/10/2018, 2:17 PMuncurry
in kotlin? That is, a function which takes a function of two arguments and returns a function which takes a single pair of arguments?gsala
12/10/2018, 2:28 PMarve
12/10/2018, 2:43 PMfun <T, U, R> uncurry(fn: (t: T, u: U) -> R): (Pair<T, U>) -> R = { args: Pair<T, U> ->
fn(args.first, args.second)
}
Will this do?gsala
12/10/2018, 2:44 PMfun <A, B, Z> ((A, B) -> Z).uncurry(): (Pair<A, B>) -> Z = { this(it.first, it.second) }
kef
12/10/2018, 2:44 PMfun <A, B, C> uncurry(f: (A, B) -> C ) = {it: Pair<A, B> -> f(it.first, it.second)}
val f1 = {a:Int, b:Int -> a+b}
f1(1, 2)
val f2 = uncurry(f1)
f2(Pair(1, 2))
kef
12/10/2018, 2:44 PMchristophsturm
12/10/2018, 5:17 PMkef
12/11/2018, 9:18 AM