Success

data class Success<out A>(val value: A) : Try<A>

Constructors

Link copied to clipboard
constructor(value: A)

Properties

Link copied to clipboard
open override val isFailure: Boolean

Returns true iff the Try is a Success.

Link copied to clipboard
open override val isSuccess: Boolean

Returns true iff the Try is a Failure.

Link copied to clipboard
val value: A

Functions

Link copied to clipboard
inline fun <B, C> combine(other: Try<B>, function: (A, B) -> C): Try<C>

Maps the given function to the values from this Success and other, or returns this if this is a Failure or other if other is a Failure.

Link copied to clipboard

Applies the given action to the error if Failure, or does nothing if Success. Returns this for chaining.

Link copied to clipboard
fun doOnSuccess(action: Consumer<in A>): Try<A>

Applies the given action to the value if Success, or does nothing if Failure. Returns this for chaining.

Link copied to clipboard
inline fun <B> flatMap(function: (A) -> Try<B>): Try<B>

Returns the given function applied to the value from this Success, or returns this if this is a Failure.

Link copied to clipboard
open override fun getOrThrow(): A

Returns the value if a Success otherwise throws the exception if a Failure.

Link copied to clipboard
inline fun <B> map(function: (A) -> B): Try<B>

Maps the given function to the value from this Success, or returns this if this is a Failure.

Link copied to clipboard
fun throwError(): Try<A>

If this is a Failure wrapping an Error then throw it, otherwise return this for chaining.

Link copied to clipboard
open override fun toString(): String