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 true if 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 T into a new value of type U using the provided mapper function.
mapError<F>(F mapper(E error)) Expected<T, F>
Transforms the error value of type E into a new error of type F using the provided mapper function.
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