20 Filter

Let's say you want every even element from a list of integer. We can right a function that does this:

Look how similar our code is! Let's abstract out the common elements

Here, p is a predicate, a function that returns a bool.

Now let's implement our even and odd functions in terms of filter!

Filter (as implemented) is not tail-recursive. Let's implement a tail recursive version of filter!