PhBastiani
09/04/2019, 7:17 AMval eitherMonad = Either.monad<String>()
fun stackSafeEitherProgram(n: Int, acc: Int) =
eitherMonad.fx.stackSafe {
val r = when {
n == 0 -> !Right(acc)
n > 0 -> n * stackSafeEitherProgram(n-1, acc).bind()
else -> !Left("Invalid number!")
}
r
}
Not sure that you can improve this type checking...