为 kotlin 尝试 monad
Try monad for kotlin
Java 8 没有提供 Try monad。这对于函数式风格的异常处理很有用。
kotlin 有现成的实现吗?或者我应该实施一个吗?
很遗憾,Kotlin 标准库中没有 Try monad。我刚学 FP,但我觉得 sealed class is what you needed to implement Try monad yourself. Also there are some libraries: Result and funKTionale.
更新。 2018 年 2 月
现在 funKTionale and Kategory merged into arrow library, which has Try 单子。
从 kotlin 1.3 开始,您可以使用 runCatching
Java 8 没有提供 Try monad。这对于函数式风格的异常处理很有用。
kotlin 有现成的实现吗?或者我应该实施一个吗?
很遗憾,Kotlin 标准库中没有 Try monad。我刚学 FP,但我觉得 sealed class is what you needed to implement Try monad yourself. Also there are some libraries: Result and funKTionale.
更新。 2018 年 2 月
现在 funKTionale and Kategory merged into arrow library, which has Try 单子。
从 kotlin 1.3 开始,您可以使用 runCatching