mapLists<R> method

Stream<List<R>> mapLists<R>(
  1. List<R> mapper(
    1. List<T>
    ), {
  2. bool skipMappedToEmpty = true,
})

Maps each list emitted by this stream using mapper.

If skipMappedToEmpty is true, non-empty lists that map to empty lists are not emitted, avoiding accidental empty list events. Incoming empty lists are preserved as-is (e.g. for refresh signals).

Implementation

Stream<List<R>> mapLists<R>(
  List<R> Function(List<T>) mapper, {
  bool skipMappedToEmpty = true,
}) async* {
  await for (final list in this) {
    if (list.isEmpty) {
      yield <R>[];
      continue;
    }
    final mapped = mapper(list);
    if (skipMappedToEmpty && mapped.isEmpty) {
      continue;
    }
    yield mapped;
  }
}