I'm not saying that your method is incorrect. I am just looking at a different form of abstraction. In the case of using the Iterator, where does it resides? I assume that is in the collection class. Then the Algorithm and the Iterator are combined into one. But then I think, this is not right. The sole purpose of an Iterator should be traversing (up, down) through the elements of the collection. Then algorithms can be defined that take iterators as an input arguments. Also I feel that Iterators should be objects themselves and contain begin and end methods (maybe even overloading ++ and --)

CollectionX ->begin (Iterator) CollectionY ->begin (Iterator) CollectionZ ->begin (Iterator) ->end (Iterator) ProgressBar Flowers Algorithms - showProgress - Bound to ProgressBar - growFlowers - Bound to Flowers code: ... use CollectionX ; use CollectionY ; use Algorithms qw( showProgress, growFlowers ) ; ... my colX = new CollectionX ; colX->... ; while( showProgress(CollectionX->begin) ) { } my colY = CollectionY ; colY->... ; while( showProgress(colY->begin) ) { } my colY = CollectionY ; colY->... ; while( growFlowers(colY->begin) ) { }

With this level of abstraction it is only needed to define iterators for each type of collection, and only one algorithm for each added functionality. Otherwise I would need to create an iterator for each added functionality for each class (in this example 6 iterators instead of 3) and repeat code 3 + 3 times. I'm not going to build examples on this, just too much work right now. But I think the method with the tie shown by hdb makes this possible and that is why I said like it so much. I hope this helped understanding where I am coming from.


In reply to Re^10: Getting for() to accept a tied array in one statement by Veltro
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.