val range = 1..100
val summary = range.intIterator.summarize
println('''Sum of elements in range [«range.start»..«range.end»] is «summary.sum»''')
Extensions to PrimitiveIterators
The primitive iterators defined in the JDK as sub-interfaces of java.util.PrimitiveIterator
do not provide combinators like the ones provided by Xtend. These combinators, however, do take some
efforts to implement. Instread, this library provides the class
de.fhg.fokus.xtensions.iteration.PrimitiveIteratorExtensions
provides methods to
create primitive streams (from java.util.stream
) for the remaining elements of a given iterator via the
extension methods streamRemaining
or parallelStreamRemaining
. Note that the method streamRemaining
does not guarantee that the elements provided by the returned stream are actually taken from the originating
iterator. If the underlying iterator implementation is known, the framework may construct a stream that may have
better characteristics in some way. If elements should actually be removed from the originating iterator, the
streamRemainingExhaustive
method can be used.
To create a summary object providing the minimum value, maximum value, average value, sum value, and count of elements,
the PrimitiveIteratorExtensions
class provides a summarize
function for all three primitive iterators.
Example:
Tip: If you want to know more about the extension methods available on IntegerRange
, have a look at chapter Extensions to IntegerRange
Tip
|
Related JavaDocs: |