Scan Operator
Rocket.scan
— Functionscan(::Type{R}, scanFn::F, seed::R) where { R, F <: Function }
scan(scanFn::F) where { F <: Function }
Creates a scan operator, which applies a given accumulator scanFn
function to each value emmited by the source Observable, and returns each intermediate result with an optional seed value. If a seed value is specified, then that value will be used as the initial value for the accumulator. If no seed value is specified, the first item of the source is used as the seed.
Arguments
::Type{R}
: the type of data of transformed value, may be or may not be the same as type of input sourcescanFn::Function
: accumulator function with(data::T, current::R) -> R
signatureseed::R
: optional initial value for accumulator function
Producing
Stream of type <: Subscribable{R}
Examples
using Rocket
source = from([ 1, 2, 3 ])
subscribe!(source |> scan(+), logger())
;
# output
[LogActor] Data: 1
[LogActor] Data: 3
[LogActor] Data: 6
[LogActor] Completed
using Rocket
source = from([ 1, 2, 3 ])
subscribe!(source |> scan(Vector{Int}, (d, c) -> [ c..., d ], Int[]), logger())
;
# output
[LogActor] Data: [1]
[LogActor] Data: [1, 2]
[LogActor] Data: [1, 2, 3]
[LogActor] Completed
See also: AbstractOperator
, RightTypedOperator
, ProxyObservable
, reduce
, logger
Description
Combines all values emitted by the source, using an accumulator function that joins a new source value with the past accumulation. This is similar to reduce
, but emits the intermediate accumulations.
Returns an Observable that applies a specified accumulator function to each item emitted by the source Observable. If a seed
value is specified, then that value will be used as the initial value for the accumulator. If no seed
value is specified, the first item of the source is used as the seed.