[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.programming

A class being BOTH a factory of iterators and an iterator

Victor Porton

9/4/2015 6:48:00 PM

Is it sane that a class which is a factory for iterators, itself to be an
iterator (a default iterator so to say)?

It may be convenient especially for Web masters which don't know what
iterator is.

Your opinion?

--
Victor Porton - http://porton...
1 Answer

Kaz Kylheku

9/4/2015 8:07:00 PM

0

On 2015-09-04, Victor Porton <porton@narod.ru> wrote:
> Is it sane that a class which is a factory for iterators, itself to be an
> iterator (a default iterator so to say)?

Not any more than for a complex_number class to also be a network_stream,
with a disconnect method. :)

> It may be convenient especially for Web masters which don't know what
> iterator is.

Programmers can be insulated from explicit use of iterator objects with
syntactic sugar. That is to say, some "for each var in obj" type construct can
compile to code which instantiats an appropriate iterator (which goes with the
type of obj). This iterator is stored in an anonymized, programmer-invisible
local variable and used implicitly by the syntax to step var through the
elements of obj.

An iterator factory can be invoved if the iterator type can't be statically
determined.

for item in obj { block }

-- translate -->

var __iter_0025 = iter_factory(typeof(obj)).instantiate(obj);

while (__iter_0025.has_more()) {
var item = __iter_0025.get_another();
{ block }
}