homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Jáchym Barvínek
Recipients Jáchym Barvínek
Date 2016年08月25日.11:42:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1472125335.99.0.627029201806.issue27858@psf.upfronthosting.co.za>
In-reply-to
Content
An identity function is sometimes useful in functional-style programming as a dummy or default value.
For example, we can sometimes see a pattern like this (e.g. in itertools.groupby):
def f(params, key=None):
 if key is None:
 key = lambda x: x
 ...
However, if we had a canonical itentity function:
def identity(x):
 return x
we could instead write:
def f(params, key=identity):
 ...
and the intended use of the function f and it's functioning would be more obvious simply from it's signature, while also saving a little code. 
As zen of Python says: Explicit is better than implicit.
Of course, we can now write:
def f(params, key=lambda x: x):
 ...
but the reason why is not used is probably that it feels a bit awkward to more people than just me.
History
Date User Action Args
2016年08月25日 11:42:16Jáchym Barvíneksetrecipients: + Jáchym Barvínek
2016年08月25日 11:42:15Jáchym Barvíneksetmessageid: <1472125335.99.0.627029201806.issue27858@psf.upfronthosting.co.za>
2016年08月25日 11:42:15Jáchym Barvíneklinkissue27858 messages
2016年08月25日 11:42:15Jáchym Barvínekcreate

AltStyle によって変換されたページ (->オリジナル) /