maybe Of
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" }
Content copied to clipboard
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() }
Content copied to clipboard
Receiver
Parameters
catch
Map thrown exceptions to some Maybe. (Returns an emptyFailure by default).
block
The code to execute.