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>>
Methods
-
filter(
bool test(T item)) → Result< List< T> > -
Available on Result<
Keeps only the elements satisfyingList< , provided by the ResultListX extensionT> >test. Errors pass through unchanged. -
firstOrError(
{String emptyMessage = 'List is empty'}) → Result< T> -
Available on Result<
Returns the first element of the wrapped list as aList< , provided by the ResultListX extensionT> >Result<T>. If the list is empty, the result becomes an Error carrying Failure.notFound withemptyMessage. -
mapList<
R> (R transform(T item)) → Result< List< R> > -
Available on Result<
Transforms each element of the wrapped list withList< , provided by the ResultListX extensionT> >transform. -
whereResult(
bool test(T item)) → Result< List< T> > -
Available on Result<
Alias for filter that reads more naturally next to mapList.List< , provided by the ResultListX extensionT> >