Created
March 29, 2018 10:27
-
-
Save axross/fbab2c5cd1d5f05126f958b41050021f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef bool Predicate(T); | |
List<T> filter<T>(List<T> list, Predicate predicate) { | |
final newList = []; | |
for (final item in list) { | |
if (predicate(item)) { | |
newList.add(item); | |
} | |
} | |
return newList; | |
} | |
void main() { | |
final filtered = filter([1, 2, 3, 4, 5], (item) => item % 2 == 1); | |
assert(filtered.length == 3); | |
print(filtered); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment