Another common task that can be succinctly solved with higher-order functions is filtering. There are several cases where you or your users are only interested in a subset of your data. In these cases, you can use the where() function to filter your data:
final onlyMs = names.where((name) => name.last.startsWith('M'));
This line iterates through every element in the list and returns true or false if the last name starts with an "M." The result of this instruction will be a new list of names that only contains the filtered items.
For higher-order functions that expect a function that returns a Boolean, you can refer to the provided function as either a test or a predicate.
where() is not the only function that filters data. There are a few others, such as firstWhere(), lastWhere(), singleWhere(), indexWhere(), and removeWhere(), which all accept the same sort of predicate function.