0

我们可以bind()在 Arrow monad 理解中使用的一种方式是“大喊大叫”(第三个示例):

/**
 * All possible approaches to running [Kind] in the context of [Fx]
 *
 * ```
 * fx {
 *   val one = just(1).bind() // using bind
 *   val (two) = just(one + 1) // using destructuring
 *   val three = !just(two + 1) // yelling at it
 * }
 * ```
 */

由于 Kotlin 的!运算符用于否定布尔值,您能解释一下它在 Arrow 中是如何以及为什么以这种方式工作的吗?

4

1 回答 1

0

我在 Kotlin 的关于运算符重载的文档中找到了答案:https ://kotlinlang.org/docs/reference/operator-overloading.html

BindSyntax覆盖 not 运算符:

interface BindSyntax<F> {

  suspend fun <A> Kind<F, A>.bind(): A

  suspend operator fun <A> Kind<F, A>.not(): A =
    bind()
}
于 2020-11-08T12:20:57.857 回答