Is this an instance of the VisitorPattern
No, but an internal iterator could be used to implement a visitor pattern by having the function object call Accept() on each element in the collection, passing in a concrete visitor. The internal iterator on its own is missing the double-dispatch aspect of the visitor pattern. -stmer
A before-and-after (conventional versus HOF) example would be helpful.
An Internal Iterator is a HigherOrderFunction
that takes a collection and a function and applies the function to every element of the collection. Usually the InternalIterator
is a member function of the collection and so doesn't require a specific collection parameter. The function parameter (usually a FunctorObject
in languages that don't support InternalIteration
natively) takes a single argument of the same type as the members of the collection.
Internal Iterators are relatively easy to use, reduce errors and hide implementation details of the collection upon which they work.
Unfortunately, in programming languages that lack a full CallWithCurrentContinuation
, they are limited to a single iteration strategy, and generally cannot iterate over more than one collection at a time.
You can turn an InternalIterator into an ExternalIterator by using a CoRoutine, rather than having a full CallWithCurrentContinuation (which is more powerful, and imho more crazy!). Is there more to this use of continuations than that? And what's an iteration strategy, such that I might have more than one of them?
An iteration strategy would be, for example, iterating by sorted order, random order, entered order, etc.
Compare with ExternalIterator
s and see InternalizeExternalIterators
for ways to avoid the limitations of Internal Iterators.
are specialized Internal Iterators.
Isn't FoldFunction simply
the internal iterator for a list? MapFunction is an instance of FoldFunction.
CategoryObjectFunctionalPatterns CategoryClosure CategoryCollections CategoryCodingConventions