Francis Girard wrote:
For the imerge function, what we really need to make the formulation clear is a way to look at the next element of an iteratable without consuming it. Or else, a way to put back "consumed" elements in the front an iteration flow, much like the list constructors in FP languages like Haskell.

It is simple to encapsulate an iterator inside another iterator class that would do just that. Here's one. The additional "fst" method returns the next element to consume without consuming it and the "isBottom" checks if there is something left to consume from the iteration flow, without actually consuming anything. I named the class "IteratorDeiterator" for lack of imagination :

[snip]

Another implementation is my peekable class:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/304373

It allows you to peek several elements ahead if that's necessary.

Steve
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to