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

Ben Finney ben+python at benfinney.id.au
Sun Mar 27 05:14:42 CEST 2011


Jan Kaliszewski <zuo at chopin.edu.pl> writes:

> 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))

Why so specific? What's wrong with ‘operator.is_(x, None)’ and
‘operator.is_not(x, None)’? Those both work today.

> 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

This one seems overkill for the standard library.

-- 
 \              “When cryptography is outlawed, bayl bhgynjf jvyy unir |
  `\                                              cevinpl.” —Anonymous |
_o__)                                                                  |
Ben Finney




More information about the Python-ideas mailing list