# Iterator

Inherits from: RHObject


An Iterator can be used to iterate a List or RecArray. For example:

Frame recs = ...
Frame rec

Frame iterator = $RHCore.Iterator.New(recs)

while IsDefined(rec=iterator.next())
	// do something with rec	
end

The class also permits iterating a collection of objects that wrap a Record (e.g., RHNode wraps a WebNodes record). For example, RHNodeQuery can be used to query all documents belonging to the current user:

Frame nodes = $RHCore.RHNodeQuery.New(prgCtx) \
							.filter('subtype', '==', $TypeDocument) \
							.filter('userid', '==', prgCtx.USession().fUserID)

An Iterator for this query can be retrieved with the iterator() method:

Frame iterator = nodes.iterator()

This can be iterated as before, but the .next() call will return an instance of RHNode instead of Record:

Frame node

while IsDefined(node=iterator.next())
	// node is an instance of RHNode
end

For performance reasons, a new object instance is not instantiated on each .next() call. Instead, a single instance is created and reused on each iteration.

# Class Methods

# Inherited methods

Destructor ErrorAssoc OKAssoc

# IsIterable

function Boolean IsIterable(Dynamic item)

Checks whether an item can be iterated with Iterator.

# Parameters
  • item - The data to check whether it can be iterated.
# Returns
  • Returns true if item can be iterated, false otherwise.

# New

function Dynamic New(Dynamic items={}, Frame obj=Undefined)

# Overrides:

New in class RHObject

# Instance Methods

# Property Methods

Property methods can be accessed with the valueForKey method.

classidentifier classname clone count counter counter0 errorassoc first hash hasnext hasprevious identityhashcode index item itematindex items iterator last methods next okassoc parentloop previous propertymethods raw reset reverse serialize string top totalcount

# Inherited methods

assert cacheMethod cacheValueForKey callSuper checkError class classIdentifier className clone deserialize endTrans identityHashCode isAccessorMethod isCached isInstanceOf isProperty isPropertyMethod methods pluck prepareForReuse propertyMethods removeFromCache reset resetCache respondsTo setCacheValueForKey setValueForKey setValueForKeyPath startTrans super valueForKey valueForKeyPath

# addField

function Frame addField(String fieldName)

# annotate

function Frame annotate(String fieldName, Dynamic keypath)

# callOnEach

function Dynamic callOnEach(String method, List args={}, Boolean foldResults=false)

# count

function Integer count()

Returns the total number of items in this iterator.

# counter

function Integer counter()

Returns the 1-based iteration count.

# counter0

function Integer counter0()

Returns the 0-based iteration count.

# dict

function Assoc dict(String keypath)

Clone is required.

# Overrides:

dict in class RHObject

# filter

function Frame filter(Dynamic keyPath, String op, Dynamic value)

# first

function Boolean first()

Returns true if on the first iteration of the loop, false otherwise.

# groupby

function Assoc groupby(String keypath)

# hash

function String hash()

# Overrides:

hash in class RHObject

# hasNext

function Boolean hasNext()

# hasPrevious

function Boolean hasPrevious()

# index

function Integer index()

# indexByKeypath

function Assoc indexByKeypath(String keyKeypath, String valueKeyPath='')

# indexOf

function Integer indexOf(Dynamic item1)

# isIndexInRange

function Boolean isIndexInRange(Integer index)

# item

function Dynamic item(Integer index=.fIndex)

# itemAtIndex

function Dynamic itemAtIndex(Integer index=.fIndex)

# items

function Dynamic items()

# iterator

function Frame iterator()

# Overrides:

iterator in class RHObject

# Returns
  • Itself, this.

# jump

function Void jump(Integer step)

# last

function Boolean last()

Returns true if on the last iteration of the loop, false otherwise.

# makeChoices

function List makeChoices(String valueKeyPath, String displayKeyPath, String nullString=Undefined)

# map

function List map(Script s, Object thisArg=this)

# next

function Dynamic next()

Returns the next item in the iterator.

# parentLoop

function Dynamic parentLoop()

# previous

function Dynamic previous()

Returns the previous item in the iterator.

# raw

function Dynamic raw(Integer index=.fIndex)

# resetSubclass

function Void resetSubclass()

# Overrides:

resetSubclass in class RHObject

# reverse

function Frame reverse()

Returns a new Iterator with the items in this iterator reversed.

# serialize

function Dynamic serialize(String serializerName=Undefined)

# Overrides:

serialize in class RHObject

# setIndex

function Frame setIndex(Integer index)

# setObject

function Frame setObject(Frame obj)

# setParentLoop

function Frame setParentLoop(Dynamic parentLoop)

# setValues

function Frame setValues(Dynamic items)

# Overrides:

setValues in class RHObject

# sort

function Dynamic sort(Dynamic args)

# sortWithFunction

function Frame sortWithFunction(Script s)

# sortWithKeyPath

function Dynamic sortWithKeyPath(Dynamic keypath, Boolean ascending=true)

# string

function String string()

# Overrides:

string in class RHObject

# toExcel

function String toExcel(List columnNames, String sheetName="Sheet1")

# top

function Dynamic top(Integer offset=1)

Returns the next item in the iterator without advancing the iteration count.

# totalCount

function Integer totalCount()

Returns the total number of items in this iterator.

Last Updated: 7/19/2019, 3:06:36 PM