CompactMap<T> extension
Extension on Iterable of nullable values, allowing removal of nulls and optional transformation.
If a transform function is provided, it is applied to each element before filtering out nulls.
Example:
final result = [1, 2, null, 3].compactMap();
print(result); // (1, 2, 3)
final transformed = [1, 2, null, 3].compactMap((e) => e == null ? null : e * 2);
print(transformed); // (2, 4, 6)
- on
-
- Iterable<
T?>
- Iterable<
Methods
-
compactMap<
E> ([E? transform(T?)?]) → Iterable< T> -
Available on Iterable<
Maps and filters outT?> , provided by the CompactMap extensionnullvalues from the iterable.