[Python-ideas] PEP 505 -- None-aware operators

אלעזר elazarg at gmail.com
Fri Oct 14 09:19:37 EDT 2016


On Fri, Oct 14, 2016 at 4:14 PM Gustavo Carneiro <gjcarneiro at gmail.com>
wrote:

> Sorry if I missed the boat, but only just now saw this PEP.
>
> Glancing through the PEP, I don't see mentioned anywhere the SQL
> alternative of having a coalesce() function:
> https://www.postgresql.org/docs/9.6/static/functions-conditional.html#FUNCTIONS-COALESCE-NVL-IFNULL
>
> In Python, something like this:
>
> def coalesce(*args):
>     for arg in args:
>         if arg is not None:
>              return arg
>     return None
>
> Just drop it into builtins, and voila.   No need for lengthy discussions
> about which operator to use because IMHO it needs no operator.
>
> Sure, it's not as sexy as a fancy new operator, nor as headline grabbing,
> but it is pretty useful.
>
>
This has the downside of not being short-circuit - arguments to the
function are evaluated eagerly.

Elazar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161014/ff067808/attachment.html>


More information about the Python-ideas mailing list