Reputation: 10956
I wrote this goofy tuplize
function:
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 f = tuplize(::foo)
val ys = xs.map(f)
It works, but I guess arrow-kt already has something nice build-in, and I just can't find it. Can you help me out? :)
(Sure, I could just use val ys = xs.map { (a, b) -> foo(a, b) }
, but in this example, the goal is to express it in point-free style.)
Upvotes: 2
Views: 323
Reputation: 775
arrow used to have such utility functions in older versions (check https://github.com/arrow-kt/arrow-core/blob/master/arrow-syntax/src/main/kotlin/arrow/syntax/function/tupling.kt)
however they are deprecated and were removed
Upvotes: 1