[Python-ideas] Adding some standalone iterator/sequence functions as methods of the iterator objects

Jan Kaliszewski zuo at chopin.edu.pl
Thu Aug 13 01:32:19 CEST 2009


12-08-2009 Manuel Alejandro Cerón Estrada <ceronman at gmail.com> wrote:

> I understand why this has been rejected. However, I still think that
> the core idea of making the pipe-filter pattern and queries more
> readable is valuable.
>
> I'm thinking on implementing this as a third party wrapper module for
> itertools and others. An QueryIter wrapper class could help to this
> purpose and It would be very easy to implement. Could be something
> like this:
>
> pairs_tasks = IterQuery(programmers).combinations(2).cycle().izip(tasks)
>
> Methods would be simple wrappers:
>
> def combinations(self, repeat):
>     return IterQuery(itertools.combinations(self, repeat))

Maybe it could be generalized? Imagine funpipe() factory function (or
with another name, doesn't matter at the moment) which could produce
proxy objects with such a feature that e.g.:

funpipe(<args0...>).fun1(<args1...>).fun2(<args2...>).fun3(<args3...>)

-- would be effectively equivalent to:

fun3(fun2(fun1(<args0...>, <args1...>), <args2...>), <args3...>)

-- where <args0...> means 0 or more positional arguments,
    and <args1-X...> means 0 or more positional and/or kw. arguments.

I hope I'm clear about what's the idea.

It could be in functools, itertools or as a built-in function...

What do you think?

*j
-- 
Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>



More information about the Python-ideas mailing list