vach
vach

Reputation: 11397

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?

Upvotes: 4

Views: 3492

Answers (2)

rell
rell

Reputation: 151

Since kotlin 1.3 you can use runCatching

Upvotes: 1

Ruslan
Ruslan

Reputation: 14640

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.

Upvotes: 6

Related Questions