public interface Stepper<A> extends StepperLike<A,Stepper<A>>
Iterator
, named hasStep
and nextStep
so they can
coexist with iterator methods. However, like Spliterator
,
steppers provide a tryStep
method to call a closure if another
element exists, a substep()
method to split into pieces, and
characteristics
and size-reporting methods that
implement the subdivision and report what is known about the remaining
size of the Stepper
. Stepper
thus naturally implements both
Iterator
and Spliterator
.
A Stepper
can present itself as a Spliterator via the spliterator
method, or as a Scala Iterator via the iterator
method. The Stepper
trait is compatible with both Spliterator
and Java's generic and
primitive iterators, so a Stepper
may already be one or both.
Subtraits NextStepper
and TryStepper
fill in the basic capability
by either implementing tryStep
in terms of hasStep
and nextStep
,
or vice versa.
Subtraits AnyStepper
, DoubleStepper
, IntStepper
, and LongStepper
implement both the Stepper
trait and the corresponding Java
Spliterator
and Iterator
/PrimitiveIterator
.
Example:
val s = Stepper.of(Vector(1,2,3,4))
if (s.hasStep) println(s.nextStep) // Prints 1
println(s.tryStep(i => println(i*i))) // Prints 4, then true
s.substep.foreach(println) // Prints 3
println(s.count(_ > 3)) // Prints 4
println(s.hasStep) // Prints `false`
Modifier and Type | Interface and Description |
---|---|
static class |
Stepper.OfDoubleSpliterator |
static class |
Stepper.OfIntSpliterator |
static class |
Stepper.OfLongSpliterator |
static class |
Stepper.OfSpliterator<A> |
static class |
Stepper.UnboxingByteStepper |
static class |
Stepper.UnboxingCharStepper |
static class |
Stepper.UnboxingDoubleStepper |
static class |
Stepper.UnboxingFloatStepper |
static class |
Stepper.UnboxingIntStepper |
static class |
Stepper.UnboxingLongStepper |
static class |
Stepper.UnboxingShortStepper |
Modifier and Type | Method and Description |
---|---|
<Acc extends AccumulatorLike<A,Acc>> |
accumulate(AccumulatesFromStepper<A,Acc> accer)
Drains the contents of this stepper into an
Accumulator or specialized variant thereof as appropriate. |
anticipateParallelism, characteristics, count, count, exists, find, fold, foldTo, foreach, hasStep, iterator, knownSize, nextStep, reduce, spliterator, substep, to, tryStep
<Acc extends AccumulatorLike<A,Acc>> Acc accumulate(AccumulatesFromStepper<A,Acc> accer)
Accumulator
or specialized variant thereof as appropriate.
This is a terminal operation.
Note: accumulation will occur sequentially. To accumulate in parallel, use a Stream
(i.e. .parStream.accumulate
).
accer
- (undocumented)