javafunctional-programmingmonadskotlin

Try monad for kotlin


Java 8 didn't provide Try monad. Which is useful for exception handling in functional style.

Is there any ready implementation in kotlin? or shall i implement one?


Solution

  • Since Kotlin 1.3 you can use runCatching
    Update: I'm agree with @Augusto about catching ERROR .
    One more argument against using this function is what it catches coroutines' cancelation exception as well kotlinx issue about it.