setWhere<K extends Object> 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> setWhere<K extends Object>(
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>[];
if (this == null) {
return tmp;
}
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;
}