bjonnh
01/07/2019, 9:24 PMimport <http://arrow.effects.IO|arrow.effects.IO>
import arrow.effects.extensions.io.monad.binding
data class Obj(val a: String)
sealed class KnownError : RuntimeException()
object DecodingError : KnownError()
fun apiCall(s: String) = IO {
"Some string"
}
fun convert(s: String): Obj? {
return Obj("Some other output")
}
fun work(s: String): IO<Obj> =
IO.run {
binding {
val output = apiCall(s)
val obj = convert(output.bind())
if (obj != null)
obj
else
raiseError<Obj>(DecodingError)
}
}