Expected<T, E> class
A type that contains either an expected value of type T or an error of type E.
Expected<T, E> is a powerful functional wrapper that mimics C++23's std::expected.
It allows for robust error handling without relying on throwing exceptions.
Constructors
- Expected.error(E error)
-
Creates an Expected containing an error.
const
- Expected.value(T value)
-
Creates an Expected containing a successful value.
const
Properties
- error → E
-
Returns the error value.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- hasValue → bool
-
Returns
trueif this object contains an expected value.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → T
-
Returns the expected value.
no setter
Methods
-
map<
U> (U mapper(T value)) → Expected< U, E> -
Transforms the expected value of type
Tinto a new value of typeUusing the providedmapperfunction. -
mapError<
F> (F mapper(E error)) → Expected< T, F> -
Transforms the error value of type
Einto a new error of typeFusing the providedmapperfunction. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
-
valueOr(
T defaultValue) → T -
Returns the expected value if it exists, otherwise returns
defaultValue.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override