outcome

inline fun <Ok : Any> outcome(block: RaiseScope<String>.() -> Ok): Outcome<Ok, String>

An alias for outcomeOf that uses a String as the Error type.

Useful for simple cases, where you fail to provide a specific error type, and just want to use any message string or Throwable.message.

Return

An Outcome instance containing the result of the block execution.

Parameters

Ok

The output type of the block, which must be a subtype of Any.

block

The block that provides the value for the success outcome.

See also


inline fun <In, Out : Any> In.outcome(block: RaiseScope<String>.(In) -> Out): Outcome<Out, String>

An alias for outcomeOf that uses a String as the Error type.

Useful for simple cases, where you fail to provide a specific error type, and just want to use any message string or Throwable.message.

Receiver

Some input type, In, passed to block.

Return

An Outcome instance containing the result of the block execution.

Parameters

Out

The output type of the block, which must be a subtype of Any.

block

The block that provides the value for the success outcome.

See also


fun <Ok : Any, Error : Any> Ok.outcome(predicate: Ok.() -> Boolean, faulter: Ok.() -> Error): Outcome<Ok, Error>

Wraps a value of type Ok as an Outcome based on a predicate.

If the predicate returns true, the value is wrapped as a Success. If the predicate returns false, the faulter function is invoked to produce an Error which is then wrapped as a Failure.

Return

An Outcome containing the value as a Success or an Error as a Failure.

Parameters

Ok

The type of the value to wrap.

Error

The type of the error produced by the faulter.

predicate

A function that determines if the value is successful.

faulter

A function that produces an error if the predicate is false.


Wrap any T as an Outcome.

Return

An Outcome containing the value as a Success or a Failure.

Parameters

T

The type of the value to wrap.