How to create a filter using a generator