T
- the type of items that can exist in the sequencepublic interface Sequence<T extends Item<?>>
Note that different implementations of Sequence might have very different performance characteristics, though all should exhibit the same behaviour. With some sequences, calling iterate() may trigger evaluation of the logic that computes the sequence, and calling iterate() again may cause re-evaluation.
Users should avoid assuming that a sequence of length one will always be represented as an instance of Item. If you are confident that the sequence will be of length one, call the head() function to get the first item.
Modifier and Type | Method and Description |
---|---|
default java.lang.Iterable<T> |
asIterable()
Get the contents of this value in the form of a Java
Iterable ,
so that it can be used in a for-each expression. |
T |
head()
Get the first item in the sequence.
|
SequenceIterator<T> |
iterate()
Get a
SequenceIterator over all the items in the sequence |
default Sequence<T> |
makeRepeatable()
Ensure that the sequence is in a form where it can be evaluated more than once.
|
default GroundedValue<T> |
materialize()
Create a
GroundedValue containing the same items as this Sequence. |
T head() throws XPathException
XPathException
- in the situation where the sequence is evaluated lazily, and
evaluation of the first item causes a dynamic error.SequenceIterator<T> iterate() throws XPathException
SequenceIterator
over all the items in the sequenceSequenceIterator
, which is
not a Iterator
) over all the itemsXPathException
- in the situation where the sequence is evaluated lazily, and
constructing an iterator over the items causes a dynamic error.default java.lang.Iterable<T> asIterable() throws XPathException
Iterable
,
so that it can be used in a for-each expression. In the general case, obtaining
the iterable may raise dynamic errors; but the Iterator
obtained
from the iterable will be error-free. Subclasses of Sequence
that
implement GroundedValue
are directly iterable, so this method is a no-op
in those cases.XPathException
default GroundedValue<T> materialize() throws XPathException
GroundedValue
containing the same items as this Sequence.
A GroundedValue
typically contains the entire sequence in memory; at
any rate, it guarantees that the entire sequence can be read without any
possibility of XPath dynamic errors arising.GroundedValue
containing the same items as this SequenceXPathException
- if evaluating the contents of the sequence fails with
a dynamic error.default Sequence<T> makeRepeatable() throws XPathException
LazySequence
and Closure
can only be evaluated
once, and this operation causes these to be grounded. However, making it repeatable
is not the same as making it grounded; it does not flush out all errors. Indeed, lazy
evaluation relies on this property, because an expression that has been lifted out of
a loop must not be evaluated unless the loop is executed at least once, to prevent spurious
errors.XPathException
- if evaluation failsCopyright (c) 2004-2020 Saxonica Limited. All rights reserved.