Created
January 17, 2020 09:55
-
-
Save raveesh-me/c06cdd9404c1241f50b1dd51c7c83680 to your computer and use it in GitHub Desktop.
dart MultiFilters
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
void main() { | |
var anda = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
var divisibleByTwo = (int i) { | |
return i % 2 == 0; | |
}; | |
var greaterThanThree = (int i) { | |
return i > 3; | |
}; | |
var aloo = multiFilters<int>(anda, [ | |
// divisibleByTwo, | |
// greaterThanThree, | |
]); | |
print(aloo); | |
} | |
typedef bool FilterFunction<T>(T t); | |
List<T> multiFilters<T>( | |
List<T> initialData, List<FilterFunction<T>> filterFunctions) { | |
var _initData = initialData; | |
filterFunctions.forEach((function) { | |
_initData = _initData.where(function).toList(); | |
}); | |
return _initData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment