[Python-Dev] RFC: generator combinator syntax

Steven D. Majewski sdm7g@Virginia.EDU
Fri, 3 Aug 2001 17:21:29 -0400 (EDT)

FYI: In the thread on comp.lang.python with the subject:

"Nested generators is the python equivalent of unix pipe cmds."

we're hashing out some ideas for functions for "the standard 
generator library" and syntax for operators to combine iterators.

This thread started after thinking about my comments on Eric's
request-for-comments on a file processing framework. 

I'm not actually in favor of following unix pipeline syntax so
closely as to use the __or__ operator -- I think it's confusing
python syntax -- but by having   'iterator | function' 
return a modified iterator, you can build iterator pipeline
chain commands. 

For example:

	Files('.') | isGif 

Files( '.' ) is a generator that recursively enumerates all the files 
	     starting from the current (unix) working directory. 

isGif = lambda s : s.lower().find( '.gif' ) >= 0 

and the operator returns the iterator that returns all of the 
 ".gif" files below the current working directory. 

I'm actually proposing "&" to be the operator to do the above.
I think "|", despite the unix convention, would be better for
alternation ( i.e. the generator that yields one from column A,
one from column (generator) B, etc. ) 

-- Steve