def keep(pred):
    """Keep only items that do not return None when pred is called. This is for
    functions that only return values in certain cases, or which return None
    for their false value."""
    def generator(coll):
        for item in coll:
            res = pred(item)
            if res is not None:
                yield res
    return generator