sdk-common / com.tomtom.online.sdk.common.functional / Try / Failure

Failure

class Failure<T : Any!> : Try<T>

Represents a failed computation that resulted in a Throwable.

Functions

cast

fun <R : Any!> cast(clazz: Class<R>): Try<R>!

equals

fun equals(other: Any?): Boolean

filter

fun filter(predicate: Predicate<in T>, ignored: Supplier<out Throwable!>): Try<T>!

flatMap

fun <R : Any!> flatMap(ignored: (in T) -> out Try<out R>!): Try<R>!

get

fun get(): T

getCause

fun getCause(): Throwable!

getChecked

fun getChecked(): T

getOrElse

fun getOrElse(defaultValue: T?): T

hashCode

fun hashCode(): Int

ifFailure

fun ifFailure(action: Consumer1<Throwable!>): Try<T>!

ifSuccess

fun ifSuccess(ignored: Consumer1<in T>): Try<T>!

isSuccess

fun isSuccess(): Boolean

map

fun <R : Any!> map(ignored: (in T) -> out R): Try<R>!

onBoth

fun <R : Any!> onBoth(other: Try<out R>, action: Consumer2<in T, in R>): Try<T>
fun <R : Any!> onBoth(otherSupplier: Supplier<Try<R>!>, action: Consumer2<in T, in R>): Try<T>

orElse

fun orElse(defaultTry: Try<T>): Try<T>!
fun orElse(supplier: Supplier<Try<T>!>): Try<T>!

recover

fun recover(function: (in Throwable!) -> out T): Try<T>!

recoverWith

fun recoverWith(function: (in Throwable!) -> Try<out T>!): Try<T>!

zipWith

fun <R : Any!, S : Any!> zipWith(other: Try<out S>, zipper: (in T, in S) -> out R): Try<R>

Inherited Functions

failure

open static fun <R : Any!> failure(throwable: Throwable): Try<R>

Creates a Failure from the given Throwable. This method deliberately allows a null throwable to be passed to conform with rules of monadic design.

filter

open fun filter(predicate: Predicate<in T>): Try<T>!

Returns a Failure if this Try represents a failed computation. Returns a Failure if the value does not satisfy the predicate or an Exception is thrown when testing the predicate. Returns Success otherwise.

getOrElse

open fun getOrElse(provider: (in Throwable!) -> T): T

Returns Success value or in case of Failure throws exception that can be built by the given function from the throwable stored in the Failure.

getOrElseThrow

open fun <E : Throwable!> getOrElseThrow(): T

Returns Success value or in case of Failure throws exception that is stored in the Failure.

open fun <E : Throwable!> getOrElseThrow(provider: (in Throwable!) -> E): T

Returns Success value or in case of Failure throws exception that can be built by the given function from the throwable stored in the Failure.

getOrNull

open fun getOrNull(): T

Returns a Success value or in case of Failure a null. This method was added to introduce a level of compatibility with APIs that expect `null` values. If it's not needed please use Try#getOrElse(Object) instead. Avoid introducing `null` in your code.

isFailure

open fun isFailure(): Boolean

Checks if the Try is a Failure.

iterator

open fun iterator(): MutableIterator<T>

of

open static fun <R : Any!> of(supplier: Supplier<out R>): Try<R>

Creates a Try from a given Supplier. The code run by the supplier can throw an RuntimeException, this exception will be caught and wrapped by the resulting Try.

ofChecked

open static fun <R : Any!> ofChecked(supplier: CheckedSupplier<out R>): Try<R>

Creates a Try from a given CheckedSupplier. The code run by the supplier can throw an Exception, this exception will be caught and wrapped by the resulting Try.

ofFailure

open static fun <R : Any!> ofFailure(supplier: Supplier<out Throwable!>): Try<R>

Creates a Failure from a given Supplier that returns a Throwable.

ofNullable

open static fun <R : Any!> ofNullable(value: R?): Try<R>

Creates a Try from a given value. If the value is null a Failure will be created containing information about a NullPointerException.

open static fun <R : Any!> ofNullable(value: R?, exception: Exception!): Try<R>

Creates a Try from a given value. If the value is null a Failure will be created with provided exception.

success

open static fun <R : Any!> success(value: R): Try<R>

Creates a Success from the given value. Please be aware that if the value is null then a null will get stored. If you don't want to store or process a potential null value please use Try#ofNullable(Object) instead.

unit

open static fun <R : Any!> unit(): (R) -> Try<R>!

Returns a function that takes a value and returns a monad of that value. The returned function will always return a Success regardless of the passed value (even null!).

when

open static fun <R : Any!> when(condition: Boolean, value: R): Try<R>

Creates a Try from the given value. A Success is returned if the given condition is met, a Failure otherwise.

open static fun <R : Any!> when(condition: Boolean, supplier: Supplier<out R>): Try<R>

Lazy equivalent of Try#when(boolean, Object). Creates a Try from the value returned by the given Supplier. A Success is returned if the given condition is met, a Failure otherwise.

open static fun <R : Any!> when(conditionSupplier: Supplier<Boolean!>, valueSupplier: Supplier<out R>, errorSupplier: Supplier<out Throwable!>): Try<R>!