maybeOf

inline fun <Ok : Any> maybeOf(catch: (throwable: Throwable) -> Maybe<Ok> = ::emptyFailure, block: RaiseScope<Unit>.() -> Ok): Maybe<Ok>

Context runner that encapsulates the result of block as a Maybe.

Note: catch will return an emptyFailure by default.

// Maybe<Int>
maybeOf { 3 }

// Maybe<String>
maybeOf { "value" }

Parameters

catch

Map thrown exceptions to some Maybe. (Returns an emptyFailure by default).

block

The code to execute.

See also


inline fun <In, Out : Any> In.maybeOf(catch: (throwable: Throwable) -> Maybe<Out> = ::rethrow, block: RaiseScope<Unit>.(In) -> Out): Maybe<Out>

Context runner that encapsulates the result of block as a Maybe.

Note: catch will return an emptyFailure by default.

// Maybe<Int>
3.maybeOf { it + 1 }

// Maybe<String>
"value".maybeOf { it.uppercase() }

Receiver

Some input type, In, passed to block.

Parameters

Out

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

catch

Map thrown exceptions to some Maybe. (Returns an emptyFailure by default).

block

The code to execute.

See also