arrow-kt中有ap2,ap3之类的功能吗?

Is there any function like ap2, ap3 in arrow-kt?

我看到了使用 cats in this post 的 scala 代码。

val a = Some(7)
val b = Some(9)
Applicative[Option].ap2(Some(add))(a,b)

我尝试将此代码迁移到 kotlin 和箭头,如下所示。

Option.applicative()
        .tupled(Some(7), Some(9))
        .ap(Some(::add))

// works but dirty
fun add(tuple: Tuple2<Int, Int>): Int = tuple.a + tuple.b

// not work, compilation error
// fun add(a: Int, b: Int): Int = a + b

如您所见,Tuple2 必须在 add 函数签名中指定。 查了arrow的官方文档,没有ap2,ap3,ap4这样的apN功能

有没有办法使用不包含Tuple2类型的第二个函数?

一旦版本 0.10 可用,Arrow 将在处理此问题的函数类型上有一个 .tupled() 方法,因此您将能够编写:

Option.applicative()
      .tupled(Some(7), Some(9))
      .ap(::add.tupled())

fun add(a: Int, b: Int) = a + b

对于最多 22 个参数的函数。