Disclaimer:如果你真的想详细地谈谈为什么Arrow是有用的,那么请go https://soundcloud.com/user-38099918/arrow-functional-library,听听从事这项工作的人的意见.(5:35min)
创建和使用该库的人想要以不同的方式使用Kotlin,而不是创建它并使用"the Option datatype similar to how Scala, Haskell and other FP languages handle optional values"的人.
This is just another way of defining return types of values that you do not know the output of.
Let me show you three versions:
nullability in Kotlin
val someString: String? = if (condition) "String" else null
object with another value
val someString: String = if (condition) "String" else ""
the Arrow version
val someString: Option<String> = if (condition) Some("String") else None
Kotlin逻辑的一个主要部分可能是永远不使用nullable types(如String?
),但是在与Java交互时需要使用它.当这样做时,您需要使用安全呼叫,如string?.split("a")
或not-null assertion string!!.split("a")
.
I think it is perfectly valid to use safe calls when using Java libraries, but the Arrow guys seem to think different and want to use their logic all the time.