Path: csiph.com!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: Kaz Kylheku Newsgroups: comp.programming Subject: Re: A class being BOTH a factory of iterators and an iterator Date: Fri, 4 Sep 2015 20:07:20 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 31 Message-ID: <20150904125307.138@kylheku.com> References: NNTP-Posting-Host: OGJi3KNpFOhM58UHZwXj0w.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org User-Agent: slrn/pre1.0.0-18 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.programming:5809 On 2015-09-04, Victor Porton 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 } }