Implement the filter primitive.