user
05/14/2017, 7:58 AMEither
type a fair bit, as a fairly firm believer in "Railway oriented programming" (https://fsharpforfunandprofit.com/rop/). How much of this can be accomplished with a library and/or tuples?
~~fun myFunc(willThrow: Boolean) throws: Int = if(willThrow) TODO() else 42~~
data class Try<T, X: Exception>{
val value: T?
val exception: X?
}
fun myFunc(): Try<Int, Exception> = Try {
if(willThrow) TODO() else 42
}
//usage:
val (value, ex) = myFunc(false)
//value or ex is nullable, use standard null-coercion to handle exceptions