Message212113
As soon as the trunk opens again, I'll add Nick's version to the itertools recipes section.
I'm disinclined to add it directly to the itertools module as a native C function for several reasons:
* The problem solved isn't that common (very little of code I've ever written or seen would be better-off if this function had been available). The OP's regex use case was shown by Martin to be better written as an explicit for-loop. I think this is probably also true in the general case.
* The module unity is about creating iterators. Consumers of iterators such as any(), all(), next(), sum(), min(), max() and others all lie elsewhere.
* For-loops are likely to be the one obvious way to do it for other variants such first_false(), first_true_raise_exception_if_not_found(),
or first_greater_than_limit(), etc.
* For the most part, the functional style of itertool composition has been a win for performance, but not for readabilty. Also, users of the module seem to suffer from having-too-many-choices. Accordingly, I only want to grow the module for cases where there is a clear win.
I would have pronounced on this one sooner but was stayed by the enthusiasm of the participants in this thread.
David said, "now I have a place in the non-test email code where using this would lead to easier-to-read code". IMO, this is telling. The bar is higher than "I would have used this one time". That doesn't make it worth having to learn and remember. |
|
Date |
User |
Action |
Args |
2014-02-24 16:09:19 | rhettinger | set | recipients:
+ rhettinger, tim.peters, loewis, mark.dickinson, ncoghlan, pitrou, ezio.melotti, r.david.murray, ethan.furman, lukasz.langa, hynek, serhiy.storchaka, raduv |
2014-02-24 16:09:19 | rhettinger | set | messageid: <1393258159.65.0.85340980924.issue18652@psf.upfronthosting.co.za> |
2014-02-24 16:09:19 | rhettinger | link | issue18652 messages |
2014-02-24 16:09:18 | rhettinger | create | |
|