in reply to Re^4: Efficient but elegant Cross-Product iterator ? (updated)
in thread Efficient but elegant Cross-Product iterator ?

Thanks, your code is indeed terser but I wouldn't really call it more elegant ;)

That's up to you ;-P

From what I understand are you caching the values for the next iteration, this brakes my semantics and might cause side effects.

Yes, but that can of course be rewritten. Though I don't understand how it could cause side effects if your "wheels" are not iterators themselves (unless of course you've got tied values or something like that)? My code is based on Higher-Order Perl, the algorithm is on page 131. If you're working on iterator stuff, the entire chapter on that might very well be worth a read.

  • Comment on Re^5: Efficient but elegant Cross-Product iterator ? (updated)

Replies are listed 'Best First'.
Re^6: Efficient but elegant Cross-Product iterator ? (updated)
by LanX (Saint) on Jun 21, 2020 at 19:30 UTC
    > If you're working on iterator stuff, the entire chapter on that might very well be worth a read.

    Thanks, I definitely will (and had)

    HOP's way to recombine iterators is from a logical perspective unrivaled.

    Unfortunately are function calls very expensive in Perl compared to pure functional languages where call optimization kicks in.

    This can make chained iterators extremely slow ...

    Apart from this - sorry to say so - do I hate using scalar iterators with undef as termination signal.

    That's a semipredicate footgun.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery