mapToSetWhere<R> method

Set<R> mapToSetWhere<R>(
  1. R toElement(
    1. T e
    ),
  2. bool test(
    1. T e
    ), {
  3. bool modifiable = false,
})

Creates a Set with all elements of this Iterable that satisfy the predicate test and modified by toElement.

The Set is modifiable if modifiable is true.

Implementation

Set<R> mapToSetWhere<R>(
  R Function(T e) toElement,
  bool Function(T e) test, {
  bool modifiable = false,
}) {
  final set = <R>{};
  for (final element in this) {
    if (test(element)) set.add(toElement(element));
  }
  return modifiable ? set : set.toUnmodifiableSet();
}