Exercise 3.21: Implemented filter in terms of flatMap.