option_result library
This is the base option_result library, containing both Option and Result
types and their helpers.
This library can be imported via:
import 'package:option_result/option_result.dart';
If you want to only import the Option or the Result types individually, do so via:
import 'package:option_result/option.dart';
// or
import 'package:option_result/result.dart';
Classes
-
Err<
T, E> - A type that represents the failure Result of something.
-
None<
T> - A type that represents the absence of a value.
-
Ok<
T, E> - A type that represents the successful Result of something.
-
Option<
T> - A type that represents the presence (Some) or absence (None) of a value.
-
Result<
T, E> - A type that represents the result of something, either success (Ok) or failure (Err).
-
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. -
OptionFutureOrUnwrap
on FutureOr<
Option< T> > -
Provides
callfunctionality to FutureOr values that complete with an Option type value. -
OptionFutureUnwrap
on Future<
Option< T> > -
Provides
callfunctionality to Future values that complete with an Option type value. -
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. -
ResultFlatten
on Result<
Result< T, E> , E> -
Provides the
flatten()method to Result type values that hold another Result. -
ResultFutureOrUnwrap
on FutureOr<
Result< T, E> > -
Provides
callfunctionality to FutureOr values that complete with a Result type value. -
ResultFutureUnwrap
on Future<
Result< T, E> > -
Provides
callfunctionality to Future values that complete with a Result type value. -
ResultTranspose
on Result<
Option< T> , E> -
Provides the
transpose()method to Result type values that hold an Option value.
Functions
-
catchOption<
T> (Option< T> fn()) → Option<T> - Executes the given function, returning the returned Option value.
-
catchOptionAsync<
T> (FutureOr< Option< fn()) → Future<T> >Option< T> > - Executes the given function asynchronously, returning the returned Option value.
-
catchResult<
T, E> (Result< T, E> fn()) → Result<T, E> - Executes the given function, returning the returned Result value.
-
catchResultAsync<
T, E> (FutureOr< Result< fn()) → Future<T, E> >Result< T, E> > - Executes the given function asynchronously, returning the returned Result value.
Typedefs
-
FutureOption<
T> = Future< Option< T> > -
Represents a Future that completes with an Option of the given type
T. -
FutureOrOption<
T> = FutureOr< Option< T> > -
Represents a FutureOr that is or completes with an Option of the given type
T. -
FutureOrResult<
T, E> = FutureOr< Result< T, E> > -
Represents a FutureOr that is or completes with a Result of the given types
T,E. -
FutureResult<
T, E> = Future< Result< T, E> > -
Represents a Future that completes with a Result of the given types
T,E.
Exceptions / Errors
- OptionError
- Represents an error thrown by a mishandled Option type value.
-
ResultError<
T, E> - Represents an error thrown by a mishandled Result type value.