option library

This is the option library, containing only the Option type and its helpers.

This library can be imported via:

import 'package:option_result/option.dart';

If you want to import both Option and Result types, consider importing the combined library:

import 'package:option_result/option_result.dart';

Classes

None<T>
A type that represents the absence of a value.
Option<T>
A type that represents the presence (Some) or absence (None) of a value.
Some<T>
A type that represents the presence of a value of type T.

Extensions

OptionFlatten on Option<Option<T>>
Provides the flatten() method to Option type values that hold another Option.
OptionPropagateShortcut on Option<T> Function()
Provides the ~ shortcut for functions that return Option to allow propagating unwrapped None values up the call stack.
OptionPropagateShortcutAsync on Future<Option<T>> Function()
Provides the ~ shortcut for asynchronous functions that return Option to allow propagating unwrapped None values up the call stack.
OptionTranspose on Option<Result<T, E>>
Provides the transpose() method to Option type values that hold a Result.
OptionUnzip on Option<(T, U)>
Provides the unzip() method to Option type values that hold a Record of two values.

Functions

propagateOption<T>(Option<T> fn()) Option<T>
Executes the given function, returning the returned Option value.
propagateOptionAsync<T>(FutureOr<Option<T>> fn()) Future<Option<T>>
Executes the given function asynchronously, returning the returned Option value.

Exceptions / Errors

OptionError
Represents an error thrown by a mishandled Option type value.