OptionConvenience<T> extension

Convenience methods for handling Options.

Help is wanted here! Please open PRs to add any methods you want! When possible, try to follow the function names in Rust for Option:

on

Methods

asNullable() → T?

Available on Option<T>, provided by the OptionConvenience extension

Returns Some.value or null for None.
map<R>(R mapper(T)) Option<R>

Available on Option<T>, provided by the OptionConvenience extension

Maps an Option
unwrapOr(T defaultValue) → T

Available on Option<T>, provided by the OptionConvenience extension

Returns Some.value if this is a Some. Otherwise, returns defaultValue (when None).
unwrapOrElse(T defaultFn()) → T

Available on Option<T>, provided by the OptionConvenience extension

Returns Some.value if this is a Some. Otherwise, calls and returns the result of defaultFn (when None).