setWhereListenable<K extends Listenable> method
The data in the list of others
is conditionally given to the current list.
If test
is true
, apply
will be executed.
Otherwise, orElse
will be executed.
Implementation
Iterable<K> setWhereListenable<K extends Listenable>(
Iterable<T> others, {
required bool Function(T original, T other) test,
required K? Function(T original, T other) apply,
K? Function(T original)? orElse,
}) {
final tmp = <K>[];
for (final original in this) {
final res = others.firstWhereOrNull((item) => test.call(original, item));
if (res != null) {
final applied = apply.call(original, res);
if (applied != null) {
tmp.add(applied);
}
} else {
final applied = orElse?.call(original);
if (applied != null) {
tmp.add(applied);
}
}
}
return tmp;
}