Skip to content
Alex Zuzin edited this page Apr 13, 2017 · 2 revisions

An ad-hoc Try can be created the usual way:

val succes = success(1)
val failure = failure(UnsupportedOperationException())

A lambda can be Try'd as follows:

val success = `try` { ->
        "the quick brown fox jumps over the lazy dog"
}
val fail = `try` {
       throw UnsupportedOperationException()
}

A Kotlin Iterable of Trys can be sequenced as follows:

val tryOfSeqs: Try<Seq<Int>> = 
    listOf(success(1), failure(NumberFormatException())).sequence()
Clone this wiki locally