Class Documentation
A Sequence
is a list of items which can be operated on and is evaluated lazily. Refer to the
Concept page for more information.
Class Details
Being part of the ZenScriptX Project, the fully qualified name for the class is zenscriptx.sequence.Sequence
.
Creating a New Instance
Refer to the Obtaining Sequences page.
Methods
The various methods available in a sequence can be divided into four categories:
- Terminal methods
- Type-changing lazy methods
- Intermediate lazy methods
- Intermediate eager methods
Each category has its own behavior and quirks, which are described in the respective category.
Moreover, in every method signature, the letters T
and R
reference the generic types that define the sequence. In
particular, T
identifies the type of the current sequence, whereas R
identifies the type of the new sequence that
gets returned in case of type-changing lazy methods.
To save up on space, the methods will be presented in a single snippet in the corresponding category with a comment above stating what the method is supposed to do, as shown in the following example snippet.
Last but not least, refer to the list of functional interfaces if you encounter any
non-primitive type (e.g. Predicate<T>
or Function<T, R>
).
Terminal methods
Terminal methods are methods that don’t return a Sequence
instance, but rather any other type of data, such as int
,
bool
, or even nothing (void
). Moreover, they can also potentially cause the evaluation of the whole Sequence
contents, though this is not required, since some methods may also terminate execution as soon as certain conditions are
met. Nonetheless, this guarantee cannot be made.
It is also impossible to continue operating on a Sequence
after a terminal method has been called, unless the sequence
was previously saved in a variable prior to the terminal method invocation.
Type-changing lazy methods
Type-changing lazy methods are methods that return a Sequence
of a different type rather than the original one,
following the result of a conversion operation (e.g. from IItemStack
to IBlockState
). Since they are lazy,
evaluation of the contents of the sequence will be done only at a later time, when the transformation actually needs to
happen due to the invocation of a terminal method or an intermediate eager method.
Since these methods are intermediate, it is possible to keep using a Sequence
after an invocation of these methods.
Intermediate lazy methods
Intermediate lazy methods are methods that return a Sequence
of the same type as the current one, and evaluation of
the method will be deferred up until a terminal method or an intermediate eager method is called, henceforth the name
“lazy”. For this exact reason, element removal or addition may (and will) not be reflected in the sequence itself up
until the sequence is fully evaluated. For this reason, any change to the arguments passed to the function may have
unintended side effects (especially for minus
and plus
calls).
Since these methods are intermediate, it is possible to keep using a Sequence
after an invocation of these methods.
Intermediate eager methods
Intermediate eager methods are methods that return a Sequence
of the same type of the current one, but the evaluation
of the method may not be deferred up until a terminal method is called. Moreover, eager methods may cause evaluation of
the whole sequence calls up until that point at any moment between their invocation and the terminal method invocation.
For this reason, it is suggested to call eager methods as sparingly as possible and let them operate on the smallest
quantity of data possible.
Since these methods are intermediate, it is possible to keep using a Sequence
after the invocation of these methods.
Operator Overloading
Sequence
s may support operator overloading in future revisions of the language. Refer to this documentation to keep
up-to-date. Note that support may require a special compiler flag to be enabled: refer to the
Experimental Flags Preprocessor for more information.
Example
The following is an example script that shows some examples that may be done with sequences. This is nowhere a complete list, but is meant more as a reference and a proof of concept.