[issue18652] Add itertools.first_true (return first true item in iterable)

2014-04-02 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
resolution:  -> fixed
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2014-04-02 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 3e2354dde892 by Raymond Hettinger in branch '3.4':
Issue #18652:  Add an itertools recipe for first_true()
http://hg.python.org/cpython/rev/3e2354dde892

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2014-04-01 Thread Joshua Bronson

Changes by Joshua Bronson :


--
nosy: +jab

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2014-02-24 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

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

I will explain my last comment. Four months ago this place was rewritten, so 
now there is no place for this function.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2014-02-24 Thread Raymond Hettinger

Raymond Hettinger added the comment:

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.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2014-02-15 Thread Ethan Furman

Changes by Ethan Furman :


--
nosy: +ethan.furman

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2014-02-14 Thread Nick Coghlan

Changes by Nick Coghlan :


--
versions: +Python 3.5 -Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-10-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

> OK, now I have a place in the non-test email code where using this would lead 
> to easier-to-read code.

Now you have not this place. ;)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-23 Thread Radu Voicilas

Changes by Radu Voicilas :


--
nosy: +raduv

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-19 Thread R. David Murray

R. David Murray added the comment:

OK, now I have a place in the non-test email code where using this would lead 
to easier-to-read code.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-18 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Hynek, thanks for your suggestion.  I would like to mull it over for a while 
before chiming in.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-18 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
assignee:  -> rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-17 Thread Hynek Schlawack

Hynek Schlawack added the comment:

Well that's the point: it's extremely handy but simple.  I wish Raymond would 
pronounce on this.  I can keep using the PyPI version for all I care, so I'm 
not going fight for it.  But with one exception there seems to be an agreement 
that it would be a very fine thing to have.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-16 Thread R. David Murray

R. David Murray added the comment:

For what it is worth, I am currently writing some email tests and it would 
certainly be convenient to have this.  Of course I *can* define it locally in 
the the test file.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Looks as too much work for too small gain (and I'm suppose the total gain is 
negative if we count all costs).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-11 Thread Antoine Pitrou

Antoine Pitrou added the comment:

> How large will be a C implementation of this one-line function?
> 
> I'm still -1 for polluting the itertools module with trivial
> combinations of existing functions.

The solution is to move the current itertools to _itertools and have a
companion itertools.py.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

How large will be a C implementation of this one-line function?

I'm still -1 for polluting the itertools module with trivial combinations of 
existing functions.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-11 Thread Hynek Schlawack

Hynek Schlawack added the comment:

So I wanted to provide a first patch to move the discussion on and realized 
that itertools appears currently to be completely inside of 
`Modules/itertoolsmodule.c`. :-/

Any volunteers? :)

--
assignee: hynek -> 
stage:  -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-10 Thread Ezio Melotti

Changes by Ezio Melotti :


--
nosy: +ezio.melotti

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-05 Thread Antoine Pitrou

Antoine Pitrou added the comment:

(but you don't have to trust me: itertools also has izip_longest() and 
combinations_with_replacement())

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-05 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I would like to chime in and say that the fact that the functions exists in SQL 
(and possibly Lisp, Snobol and PHP) sells me on the idea!

Okay, only joking, but I do think this is a useful addition.
"first_true" should be its name, but itertools already has a tradition of 
nonunderscorednames, so it should be "firsttrue", which may look weird because 
of the doubled t.

--
nosy: +pitrou

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-05 Thread Hynek Schlawack

Hynek Schlawack added the comment:

> +1 on the name 'first_true'.  Does exactly what it says on the tin.

I fully agree.

***

I assume what's missing now is a permission from Raymond to mess with his turf?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-05 Thread Mark Dickinson

Mark Dickinson added the comment:

+1 on the name 'first_true'.  Does exactly what it says on the tin.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18652] Add itertools.first_true (return first true item in iterable)

2013-08-04 Thread Nick Coghlan

Nick Coghlan added the comment:

I concede Tim's point about itertools already using underscores where it 
improves readability of a name :)

So, the latest state of the proposal is to add the following, preferably 
directly to the module, but at least as a recipe in the itertools docs:

def first_true(iterable, default=None, pred=None):
"""Returns the first true item in the iterable

If no such item is found, returns *default*
If *pred* is not None, returns the first item
for which pred(item) is true.
"""
return next(filter(pred, iterable), default)

--
title: Add itertools.coalesce -> Add itertools.first_true (return first true 
item in iterable)

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com