Higher-order Function Filter Assignment
Contents
Motivation
In this studio you will be building the first ballot inductee to the Dan Grossman Hall of Fame of Higher Order Functions: filter.
This studio will give us the opportunity to work with the standard Java for-each loop, generics, interfaces, and lambda expressions.
With filter we get to use the for each loop and invoke a method on a generic type interface.
With filterEvens and filterWordsWhichContainAll5Vowels we get to invoke filter with lambda expressions.
Background
Mistakes To Avoid
Code to Implement
filter
| class: | FilterUtils.java | |
| methods: | filter | |
| package: | hof.filter.group | |
| source folder: | student/src/main/java |
method: public static <E> List<E> filter(Predicate<E> predicate, List<E> list)
(sequential implementation only)
This classic high level function returns a list with the elements of list for which predicate's test method returns true. The predicate's test method is applied to each element in order.
clients
| class: | FilterClients.java | |
| methods: | filterEvens filterWordsWhichContainAll5Vowels |
|
| package: | hof.filter.group | |
| source folder: | student/src/main/java |
We created a couple of utility methods which invoke filter with a custom lambda.
filterWordsWhichContainAll5Vowels
method: public static List<String> filterWordsWhichContainAll5Vowels(List<String> words)
(sequential implementation only)
Useful method: str.indexOf(ch)
filterEvens
method: public static List<Integer> filterEvens(List<Integer> xs)
(sequential implementation only)
Testing Your Solution
Correctness
| class: | _FilterTestSuite.java | |
| package: | hof.filter.group | |
| source folder: | testing/src/test/java |