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

MRAB python at mrabarnett.plus.com
Sun Mar 27 04:44:16 CEST 2011


On 27/03/2011 03:30, Jan Kaliszewski wrote:
> Hello.
>
> 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?
> *j
>
I think that suggestion 2 is a strange one! :-)



More information about the Python-ideas mailing list