Method get_iterator()


Method get_iterator

Iterator get_iterator(function(:void)|object|array|mapping|multiset|string data, mixed ... args)

Description

Creates and returns a canonical iterator for data.

Returns
data can have any of the following types:
object

If data is an object with lfun::_get_iterator defined then that function will be called with the arguments args to create the iterator.

If data is an object that lacks lfun::_get_iterator then it is assumed to already be an iterator object. In this case args will be ignored (note this behavior may be changed).

The iterator object is then checked whether it has lfun::_iterator_next() in which case it will simply be returned. Otherwise an attempt to wrap it in a CompatIterator will be performed.

array

If data is an array, an Array.Iterator object will be returned.

function(:void)

If data is a function, a Function.Iterator object will be returned.

mapping

If data is a mapping, a Mapping.Iterator object will be returned

multiset

If data is a multiset, a Multiset.Iterator object will be returned

string

If data is a string, a String.Iterator object will be returned

Note

This function is used by foreach to get an iterator for an object.

See also

Iterator, lfun::_get_iterator