maybe
inline fun <Ok> maybe(catch: (Exception) -> Maybe<Ok> = ::emptyFailure, scope: RaiseScope<Any?> = DefaultRaiseScope(), block: RaiseScope<Any?>.() -> Ok): Maybe<Ok>
Runs block inside a RaiseScope and returns a Maybe.
The error type is always mapped to Unit; use raise to short-circuit with an absent value.
Warning: Does not propagate kotlinx.coroutines.CancellationException — use maybeOf in suspend contexts.
// Maybe<String> — success
val m: Maybe<String> = maybe { "hello".uppercase() }
// Maybe<Int> — absent
val n: Maybe<Int> = maybe { raise { Unit } }Content copied to clipboard
Parameters
block
The block to execute within the scope.