Result<T, E> class sealed

Encapsulates either a result (value of generic type T) or an error (value of generic type E).

Implementers
Available extensions

Properties

errorOrNull → E?

Available on Result<T, E>, provided by the NullResultExtensions extension

Returns the error if it exists, otherwise null
no setter
firstOrNull → T?

Available on ListResult<T, E>, provided by the ListResultExtensions extension

Returns the list if it is success null otherwise
no setter
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool

Available on IterableResult<T, E>, provided by the ListResultExtensions extension

Returns true if the result is not successful or the list is empty.
no setter
isError bool
Whether or the not the result was an error
no setter
isNotEmpty bool

Available on IterableResult<T, E>, provided by the ListResultExtensions extension

Returns true if this instance represents a success result and there are itemse in the list.
no setter
isSuccess bool
Whether or not that the result was a success
no setter
lengthOrNull int?

Available on ListResult<T, E>, provided by the ListResultExtensions extension

Returns the length of the list if it is success null otherwise
no setter
resultOrNull → T?

Available on Result<T, E>, provided by the NullResultExtensions extension

Returns the result a the specified value
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

bind<U>(Result<U, E> f(T)) Result<U, E>

Available on Result<T, E>, provided by the ResultExtensions extension

Performs a bind operation and returns a new instance with a new type. The 'bind' method allows chaining operations that may fail.
firstWhereOrNull(bool predicate(T)) → T?

Available on ListResult<T, E>, provided by the ListResultExtensions extension

Returns the first value in the list if it is success null otherwise
iterableOr(Iterable<T> orElse) Iterable<T>

Available on IterableResult<T, E>, provided by the ListResultExtensions extension

Returns the result if it is a success, or the result of orElse
lengthOr(int length) int

Available on IterableResult<T, E>, provided by the ListResultExtensions extension

Returns the length of the list if it is a success, or length
map<U>(U f(T)) Result<U, E>

Available on Result<T, E>, provided by the ResultExtensions extension

The 'map' method transforms the successful value without changing the error.
mapOrNull<U>(U transform(T)) → U?

Available on Result<T, E>, provided by the NullResultExtensions extension

Returns a transformed value or null
match<U>({required U onSuccess(T), required U onError(E)}) → U

Available on Result<T, E>, provided by the ResultExtensions extension

Achieves the same thing as a switch expression with pattern matching. You should consider using a switch expression, but sometimes the match function is simpler
merge<M, J>(Result<J, E> other, M onJoin(T, J)) Result<M, E>

Available on Result<T, E>, provided by the ResultExtensions extension

Performs a merge operation and returns a new instance of M.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resultOr(T or) → T

Available on Result<T, E>, provided by the ResultExtensions extension

Returns the result a the specified value
sorted<M extends IterableResult<T, E>>(int compare(T a, T b), {required Iterable<T> onSuccess(Iterable<T>)}) IterableResult<T, E>

Available on IterableResult<T, E>, provided by the ListResultExtensions extension

Performs a sort operation and returns a new instance of M.
takeOrNull(int i) Iterable<T>?

Available on ListResult<T, E>, provided by the ListResultExtensions extension

Returns the first n elements of the list if it is success or null
toString() String
A string representation of this object.
inherited
where(bool predicate(T), {required Iterable<T> onError(E)}) Iterable<T>

Available on IterableResult<T, E>, provided by the ListResultExtensions extension

Performs a filter operation and returns a new instance of T.
whereOrNull(bool predicate(T)) Iterable<T>?

Available on ListResult<T, E>, provided by the ListResultExtensions extension

Returns the filtered elements of the list if it is success or null

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator >>(Result<T, E> transform(T)) Result<T, E>

Available on Result<T, E>, provided by the ResultExtensions extension

Performs a bind operation and returns a new instance.
operator |(T or) → T

Available on Result<T, E>, provided by the ResultExtensions extension

Returns the success value if it exists, otherwise returns or