count method
Return a number of the existing elements by a specific predicate
example:
final aboveTwenty =
User(33, "chicko"),
User(45, "ronit"),
User(19, "amsalam"),
.count((user) => user.age > 20); // 2
Implementation
int count([bool predicate(T element)?]) {
var count = 0;
if (predicate == null) {
return length;
} else {
for (var current in this) {
if (predicate(current)) {
count++;
}
}
}
return count;
}