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

Masklinn masklinn at masklinn.net
Sun Mar 27 16:43:18 CEST 2011

On 2011-03-27, at 05:14 , Ben Finney wrote:
> 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.
It would be nice if the binary pseudo-operators in ``operator`` supported right sections though: what would be really nifty here would be to write

    predicate_user(operator.is_(None), collection)

and have it behave as

    predicate_user(lambda value: operator.is_(value, None), collection)

(note: order is important, I think the most common use case for non-commutative operator sections is to fix the second operand).

This would not only obviate the purported need for an ``is_none`` operator method, it would make operator far more interesting for all higher-order tasks.

More information about the Python-ideas mailing list