ResultListX<T> extension

Extensions that operate on the elements inside a successful list result.

Lets you transform / filter the underlying collection without explicitly pattern-matching on the Result wrapper:

final names = users.mapList((u) => u.name);     // Result<List<String>>
final adults = users.filter((u) => u.age >= 18); // Result<List<User>>
on

Methods

filter(bool test(T item)) Result<List<T>>

Available on Result<List<T>>, provided by the ResultListX extension

Keeps only the elements satisfying test. Errors pass through unchanged.
firstOrError({String emptyMessage = 'List is empty'}) Result<T>

Available on Result<List<T>>, provided by the ResultListX extension

Returns the first element of the wrapped list as a Result<T>. If the list is empty, the result becomes an Error carrying Failure.notFound with emptyMessage.
mapList<R>(R transform(T item)) Result<List<R>>

Available on Result<List<T>>, provided by the ResultListX extension

Transforms each element of the wrapped list with transform.
whereResult(bool test(T item)) Result<List<T>>

Available on Result<List<T>>, provided by the ResultListX extension

Alias for filter that reads more naturally next to mapList.