The state of the scan before any elements have been processed
An element in the stream to process
The state of the scan before processing i
The output of the scan corresponding to processing i with state stateBeforeProcessing, along with the result of updating stateBeforeProcessing with the information from i.
The type of the input collection
The type of the output collection
Given inputs as a collection of the form [a_1, ..., a_n]
the output will be a collection of the form:
[o_1, ..., o_n]
where
(o_(i+1), state_(i+1)) = presentAndNextState(a_i, state_i)
and state_0 = initialState
.
Takes the output of this scan and feeds as input into scan2.
Takes the output of this scan and feeds as input into scan2.
If this Scan's apply method is given inputs [a_1, ..., a_n]
resulting in outputs of
the form [o_1, ..., o_n]
, and scan2.apply([o_1, ..., o_n] = [p_1, ..., p_n]
then
compose
will return a scan which returns [p_1, ..., p_n]
.
Given a scan that takes compatible input to this one, pairwise compose the state and outputs of each scan on a common input stream.
Given a scan that takes compatible input to this one, pairwise compose the state and outputs of each scan on a common input stream.
If this Scan's apply method is given inputs [a_1, ..., a_n] resulting in outputs of
the form [o_1, ..., o_n]
, and scan2.apply([a_1, ..., a_n] = [p_1, ..., p_n]
then
join
will return a scan whose apply method returns [(o_1, p_1), ..., (o_2, p_2)]
.
In other words: scan.join(scan2)(foo) == scan(foo).zip(scan2(foo))
For every foo
, scan.joinWithIndex(foo) == scan(foo).zipWithIndex
.
For every foo
, scan.joinWithIndex(foo) == scan(foo).zipWithIndex
.
If this Scan's apply
method is given inputs [a_1, ..., a_n]
resulting in outputs
of the form [o_1, ..., o_n]
, return a scan that whose apply method, when given the same input, will return
[(o_1, 1), ..., (o_n, n)]
.
Return a scan that is semantically identical to
this.join(Scan.identity[I1])
, but where we don't pollute the State
by pairing it
redundantly with Unit
.
Return a scan that is semantically identical to
this.join(Scan.identity[I1])
, but where we don't pollute the State
by pairing it
redundantly with Unit
.
If this Scan's apply
method is given inputs [a_1, ..., a_n]
resulting in outputs
of the form [o_1, ..., o_n
, then this results in a Scan whose apply
method
returns [(o_1, a_1), ..., (o_n, a_n)]
when given the same input.
Return a scan whose output is paired with the state of the scan after each input updates the state.
Return a scan whose output is paired with the state of the scan after each input updates the state.
If this Scan's apply
method is given inputs [a_1, ..., a_n]
resulting in outputs
of the form [o_1, ..., o_n]
, where (o_(i+1), state_(i+1)) = presentAndNextState(a_i, state_i)
and state_0 = initialState,
return a scan that whose apply method, when given inputs
[a_1, ..., a_n] will return
[(o_1, state_1), ..., (o_n, state_n]
.
Return a scan whose output is paired with the state of the scan before each input updates the state.
Return a scan whose output is paired with the state of the scan before each input updates the state.
If this Scan's apply
method is given inputs [a_1, ..., a_n] resulting in outputs
of the form [o_1, ..., o_n]
, where (o_(i+1), state_(i+1)) = presentAndNextState(a_i, state_i)
and state_0 = initialState
,
return a scan that whose apply method, when given inputs [a_1, ..., a_n]
will return
[(o_1, state_0), ..., (o_n, state_(n-1))]
.
Return a new scan that is the same as this scan, but with a different initialState
.
If iter = Iterator(a_1, ..., a_n)
, return:
state_0 = initialStateIterator(o_1, ..., o_n)
where
(o_(i+1), state_(i+1)) = presentAndNextState(a_i, state_i)
and
Compose two scans pairwise such that, when given pairwise zipped inputs, the resulting scan will output pairwise zipped outputs.
Compose two scans pairwise such that, when given pairwise zipped inputs, the resulting scan will output pairwise zipped outputs.
If this Scan's apply method is given inputs [a_1, ..., a_n]
resulting in outputs of
the form [o_1, ..., o_n]
, and scan2.apply([b_1, ..., b_n] = [p_1, ..., p_n]
then
zip
will return a scan whose apply method, when given input
[(a_1, b_1), ..., (a_n, b_n)]
results in the output [(o_1, p_1), ..., (o_2, p_2)]
.
In other words: scan.zip(scan2)(foo.zip(bar)) == scan(foo).zip(scan2(bar))
The Scan trait is an alternative to the
scanLeft
method on iterators/other collections for a range of of use-cases wherescanLeft
is awkward to use. At a high level it provides some of the same functionality asscanLeft
, but with a separation of "what is the state of the scan" from "what are the elements that I'm scanning over?". In particular, when scanning over an iterator withN
elements, the output is an iterator withN
elements (in contrast to scanLeft'sN+1
).If you find yourself writing a
scanLeft
over pairs of elements, where you only use one element of the pair within thescanLeft
, then throw that element away in amap
immediately after the scanLeft is done, then this abstraction is for you.The canonical method to use a scan is
apply
.The type of elements that the computation is scanning over.
The output type of the scan (typically distinct from the hidden
State
of the scan).