Is there a function akin to `uncurry` in kotlin? T...
# announcements
m
Is there a function akin to
uncurry
in kotlin? That is, a function which takes a function of two arguments and returns a function which takes a single pair of arguments?
g
I don't think the stdlib would have something like this. Sounds like something #C5UPMM0A0 would have. Otherwise. I think you could easily make that function yourself
a
Copy code
fun <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?
g
@arve beat me to it. As an extension function:
fun <A, B, Z> ((A, B) -> Z).uncurry(): (Pair<A, B>) -> Z = { this(it.first, it.second) }
k
Copy code
fun <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))
Damn 😉
🙂 1
c
im what language does uncurry do that?
k