Iterator

"intersystems-iris". Iterator

This class implements the Node.js iterator protocol on an IRIS global array node (implements the [Symbol.iterator] function. Depending on the iteration mode activated by a call to functions keys, values, entries, nodes and nodeEntries, it will trigger iteration over subscripts, values, subscirpt-value pairs, nodes and subscript-node pairs respectively) . It can be used to iterate over the contents of IRISGlobalNode, which behaves like a virtual dictionary representing the immediate children of a global array node.

Methods

# entries() → {module:"intersystems-iris".Iterator}

Sets the iterator return type to return entries where each value is an array containing the subscript and node value, returns this for chaining and for direct usage in for-of loops.

Tutorials:

# keys() → {module:"intersystems-iris".Iterator}

Sets the iterator return type to return keys only (subscripts), returns this for chaining and for direct usage in for-of loops.

Tutorials:

# next() → {any}

Positions the iterator at the next sibling node in collation order and return an object containing done and value properties. If the iterator is at end then done is true, otherwise it is false. The value property returned when done is false is either the subscript, the node value, or an array whose first element is the subscript and the second is the global node value. The return value type defaults to the array containing the subscript and value. The return type can be changed by invoking the entries(), keys(), or values() methods.

Tutorials:
Returns:
Type
any

# nodeEntries() → {module:"intersystems-iris".Iterator}

Sets the iterator return type to return nodeEntries where each value is an array containing the subscript and sub-node (IRISGlobalNode), returns this for chaining and for direct usage in for-of loops.

Tutorials:

# nodes() → {module:"intersystems-iris".Iterator}

Sets the iterator return type to return only sub-nodes (IRISGlobalNode), returns this for chaining and for direct usage in for-of loops.

Tutorials:

# reversed() → {module:"intersystems-iris".Iterator}

Reverses the iterator, returns this for chaining and for direct usage in for-of loops.

Tutorials:

# startFrom(subscript) → {module:"intersystems-iris".Iterator}

Positions the iterator to start from subscript, returns this() for chaining. After calling this method, use next() to advance the iterator to the next defined sub-node in alphabetic collating sequence.

Parameters:
Name Type Description
subscript any

the value of the subscript where the iterator is to be positioned

Tutorials:
Example
// For example, for the following global and iterator:
//  ^gbl("a")=11
//  ^gbl("b")=22
//  ^gbl("e")=55
itr = iris.iterator("^gbl")
 
// The starting position may be a valid sub-node, in which case the next sub-node will be the next valid one.

 itr.startFrom("a")
 for (let pair of itr) {
   let [sub, val] = pair
    console.log(sub, '->', val) 
 }
 // prints: 
 //   b -> 22
 //   e -> 55
 

// The starting position may also be an invalid sub-node, in which case the next sub-node will be the 
// first valid one in alphabetic collating sequence after the given subscript.

 itr.startFrom("c")
 for (let pair of itr) {
   let [sub, val] = pair
   console.log(sub, '->', val) // prints: e -> 55
 }

// Calling this method with undefined as an argument is the same as using the default starting position, 
// which is just before the first node, or just after the last node, depending on the iterator direction.

# subscripts() → {module:"intersystems-iris".Iterator}

Alias for the keys() function. Sets the iterator return type to return keys only (subscripts), returns this for chaining and for direct usage in for-of loops.

Tutorials:

# values() → {module:"intersystems-iris".Iterator}

Sets the iterator return type to return only values, returns this for chaining and for direct usage in for-of loops.

Tutorials: