Server-Side JavaScript
In the new version of Server-Side JavaScript, ValueIterator
has been replaced by Sequence
. The ValueIterator
interface used to represent sequences of value in MarkLogic 8 has been replaced by the new Sequence
interface. A Sequence
is a JavaScript Iterable object. All functions which previously operated on or returned a ValueIterator
now use a Sequence
instead.
In many cases, this change is transparent to your code. However, code that depends on the following ValueIterator properties and methods must be changed:
ValueIterator.next
- Use afor..of
loop to iterate over a Sequence. Usefn.head
if you just want to pick off the first or only value in a Sequence.ValueIterator.count
- Usefn.count
instead.ValueIterator.clone
- No longer needed. You can iterate over the sameSequence
multiple times.
To prepare your code for a possible mixed environment, you might use a safe coding pattern similar to this:
var list = xdmp.arrayValues(...); if (list instanceof Sequence) { ... ML9 idiom ... } else { ... ML8 idiom ... }
See Sequence in the JavaScript Reference Guide and Sequence in the MarkLogic Server-Side JavaScript Function Reference for more information.