[Python-ideas] Two small functional-style-related improvements

Jan Kaliszewski zuo at chopin.edu.pl
Sun Mar 27 04:30:41 CEST 2011


IMHO it'd be nice...

1. ...to add:

* operator.is_none -- equivalent to (lambda x: x is None))
* operator.is_not_none -- equivalent tolambda x: x is not None))

...making using 'is None'/'is not None' tests with any(), all(),
filter(), itertools.takewhile/dropwhile() more convenient and readable
(possibly also optimised for speed).

2. ...to add:

* operator.anti_caller (or e.g. functools.negator?) -- equivalent to:

def anti_caller(func):
    def call_and_negate(*args, **kwargs):
        return not func(*args, **kwargs)
    return call_and_negate

What do you think?

More information about the Python-ideas mailing list