Hi. :slightly_smiling_face: I'm trying to find ou...
# arrow
t
Hi. 🙂 I'm trying to find out, how to use arrow-kt to convert a function taking two parameters into a function taking a pair. I wrote this goofy
tuplize
function:
Copy code
fun foo(x: Int, y: Int) = 3 * x + 2 * y + 1

fun <T, U, R> tuplize(f: (T, U) -> R): ((Pair<T, U>) -> R) = { (a, b): Pair<T, U> -> f(a, b) }

val xs = listOf(Pair(1, 2), Pair(42, 23))

val ys = xs.map(tuplize(::foo))
It works, but I guess arrow-kt already has something nice build-in, and I just can't find it. Can somebody help me out?
a
I think there’s nothing in Arrow currently. There are
curry
and
uncurry
function, but those change between
(A, B) -> C
and
(A) -> (B) -> C
t
Thanks. I seems like, in the past, there was something like that (or at least planned), called
.tupled()
(https://stackoverflow.com/a/57257548). I wonder why the idea did not survive.
a
I think functions with
Pair
are less useful in Kotlin than in other languages because the language already has the notion of “having two arguments”