Why doesn't the Kotlin standard library provide so...
# language-proposals
k
Why doesn't the Kotlin standard library provide something like Either? They already halfway provide it with Result, but as Result only takes a throwable it doesn't feel very useful. Why not just make Result be Result<out A, out B> ?
👍 2
👍🏻 1
r
So...
Pair
?
k
If Pair were to have the same functionality as Result you would have to implement a lot of extension functions for it, such as isFirst, isSecond, mapFirst, mapSecond and so on.
r
Ah, I misread. I definitely need more sleep.
s
Arrow has an Either type, if you want. In general, the stdlib has more general stuff; FP stuff is mostly in Arrow
👍 1
j
you can mix sealed classes / interfaces with Result, then you get the best of both worlds
Copy code
sealed interface Blah {
	data class Success(val id: String) : Blah
	data class Error1(override val message: String) : Exception(message), Blah {
		override fun fillInStackTrace(): Throwable = this
	}
	data class Error2(override val message: String) : Exception(message), Blah {
		override fun fillInStackTrace(): Throwable = this
	}
}
and if you override the fillInStackTrace, you avoid the performance penalty of Exceptions