def filter(self, function, new_collection, **kwargs):
        """
        Filters a collection into a new collection with a given function.

        | Arguments:
        | ``function`` -- The function used for filtering.
        | ``new_collection`` -- The name of the collection to insert the new values into.  
            Any existing values will be deleted.
            If ``None``, values are filtered in the same collection.

        | Keyword arguments:
        | ``create_if_missing`` -- when False a ValueError is raised if the new collection doesn't exist
        | ``error_if_exists`` -- When True a ValueError is raised if the new collection already exists 
        """
        collection = None
        if new_collection in [None, self.name]:
            collection = self
            new_keys = []
            for key in self.keys:
                if function(decode(self.db.get(key))):
                    new_keys.append(key)
                else:
                    self.db.delete(key)
            self.keys = new_keys

        else:
            collection = self.parent_db.collection(new_collection, reset_collection=True, **kwargs)
            for instance in self:
                if function(instance):
                    collection.append(instance)

        return collection
dataset/ETHPy150Open corbt/pypeline/pypeline/DB.py/Collection.filter/original