Details of the Iterator object - Maple Programming Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Mathematics : Discrete Mathematics : Combinatorics : Iterator : Iterator/Details

Details of the Iterator object


Common Methods

Standard Methods


Common Methods

Each iterator constructed by this package is a Maple object with the following common methods.

ModuleApply : makes the object an appliable object factory. It calls the Object constructor and passes its arguments to the object's ModuleCopy method.

ModuleCopy(self,proto,...) : used to copy an object; see ModuleCopy.

ModuleIterator(self) : returns the two procedures, hasNext and getNext used to implement an iterator; see ModuleIterator. The iterators constructed by this package violate one of the specifications: calling hasNext consecutively, without a call to getNext, does not necessarily return the same value. Each call to hasNext advances the iterator. The reason for this is efficiency; these iterators reuse an Array as output, so there is no need to call getNext.

length(self) : returns the length of the output array of the iterator self. For most iterators, this is a fixed value, but for a few this changes with each iteration.

anditer(p,self,...) : applies the predicate p predicate to each iteration. Returns false immediately if any iteration returns false, otherwise returns true. Optional arguments are passed to the predicate, p.

oriter(p,self,...) : applies the predicate p predicate to each iteration. Returns true immediately if any iteration returns true, otherwise returns false. Optional arguments are passed to the predicate, p.

output(self) : returns the Array used to store the output result.

Standard Methods

Many of the iterators have the following methods.

Number(self) : return the total number of iterations that the iterator generates if it starts from rank one.

Rank(self,L) : compute the rank of L.  If L is not passed, use the current rank of self.

Unrank(self,rnk) : return the output of self corresponding to rank rnk.



Construct an iterator that generates all permutations of the integers from one to five.


Compute the number of iterations.




Test whether the sum of the first and last elements of any permutation equals three, then display the permutation and its rank that meet the criteria.










Verify all permutations sum to 15.




Display the length of the output.




See Also