The sole purpose of an Iterator should be traversing (up, down) through the elements of the collection.

But that's what the OP wants, assuming the code the OP wants to execute for each element specifically fetches or generates the element to be returned.

If that's not what the OP wants, there's no point to their wrapper, so there's no point to a tied array or iterator. They should simply place the logic in the loop itself.

The rest of your post makes no sense. You only need three implementations with an iterator if you have three implementations with a tied array since the tied array approach is literally being used as an iterator (a role it is badly equipped to handle). The tied array is pure needles complexity and overhead, the very thing programmers should be avoiding. It adds absolutely no value.

Tied arrays are a hack that should only be used to shoehorn logic into existing bad code. The very idea of a tied variable (to make code look like variable) is a bad practice. They should be used as a last resort. They should definitely be avoided when they are costly and don't provide any benefits like in this case.


In reply to Re^11: Getting for() to accept a tied array in one statement by ikegami
in thread Getting for() to accept a tied array in one statement by perlancar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.