filter method
returns if value is not empty and matches given function f.
example
int? a = 2;
int? b = 3;
int? c = null;
a.filter((element) => element %2 == 0) // => 2
b.filter((element) => element %2 == 0) // => null
c.filter(...) // => null
Implementation
T? filter(bool Function(T) f) {
if (this == null) {
return null;
} else {
if (f(this!)) {
return this!;
} else {
return null;
}
}
}