Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 879
vach Avatar asked Mar 13 '23 22:03

vach


2 Answers

Unfortunately there is no Try monad in Kotlin standard library. I'm just learning FP, but i think sealed class is what you needed to implement Try monad yourself. Also there are some libraries: Result and funKTionale.

Upd. Feb 2018

Now funKTionale and Kategory merged into arrow library, which has Try monad.

like image 85
Ruslan Avatar answered Mar 25 '23 00:03

Ruslan


Since kotlin 1.3 you can use runCatching

like image 30
rell Avatar answered Mar 25 '23 00:03

rell