Sum Operator

Base.sumFunction
sum(; from = nothing)

Creates a sum operator, which applies a sum accumulator function over the source Observable, and returns the accumulated result when the source completes, given an optional initial value.

The sum operator is similar to reduce(T, T, +) (see reduce).

Arguments

  • from: optional initial accumulation value, if nothing first value will be used instead

Producing

Stream of type <: Subscribable{L} where L refers to type of source stream

Examples

using Rocket

source = from([ i for i in 1:42 ])
subscribe!(source |> sum(), logger())
;

# output

[LogActor] Data: 903
[LogActor] Completed
using Rocket

source = from([ i for i in 1:42 ])
subscribe!(source |> sum(from = 97), logger())
;

# output

[LogActor] Data: 1000
[LogActor] Completed

See also: AbstractOperator, InferableOperator, ProxyObservable, reduce, logger

source

Description

sum operates on an Observable of objects on which + is defined. When the source Observable completes, it emits the sum of all previous items. The sum operator is similar to reduce(T, T, +) (see reduce).

See also

Operators, reduce