Hm maybe there is something worthwhile here. I implemented a Python version 
with the same semantics as itertools.product, except only consuming the 
iterators when absolutely necessary; still only consuming each iterator once, 
but building its pools incrementally.  See 
https://gist.github.com/sweeneyde/fb6734d7b9f7d17e132c28af9ecb6270

    from itertools import count
    it = LazyProductObject(count(0), count(0), "ab", repeat=3)
    assert next(it) == (0, 0, "a", 0, 0, "a", 0, 0, "a")
    assert next(it) == (0, 0, "a", 0, 0, "a", 0, 0, "b")
    assert next(it) == (0, 0, "a", 0, 0, "a", 0, 1, "a")
    assert next(it) == (0, 0, "a", 0, 0, "a", 0, 1, "b")
    assert next(it) == (0, 0, "a", 0, 0, "a", 0, 2, "a")
    assert next(it) == (0, 0, "a", 0, 0, "a", 0, 2, "b")

It looks like it could be made to have a similar tight loop as the current 
implementation if we decided to re-write it in C.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/HCX35TWZRDUY7LMGLOERWPVX6ZRICWRS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to