Streams.Accumulator Class
Extends Streams.Stream
Defined in:
samsara/streams/Accumulator.js:9
Accumulator is a Stream that accumulates a value given by a number or array of numbers.
It emits start
, update
and end
events.
Constructor
Streams.Accumulator
(
-
[sum]
-
[options]
Parameters:
Example:
var accumulator = new Accumulator(0);
// this gives the total displacement of mouse input
accumulator.subscribe(mouseInput.pluck('delta'));
Methods
filter
(
-
filterFn
Filter converts the current stream into a new stream
that only emits if the filter condition is satisfied.
The function should return a Boolean.
Parameters:
-
filterFn
FunctionFunction to filter event payload
map
(
-
mapperFn
Map converts the current stream into a new stream
with a modified (mapped) data payload.
Parameters:
-
mapperFn
FunctionFunction to map event payload
pluck
(
-
key
Pluck is an opinionated mapper. It projects a Stream
onto one of its return values.
Useful if a Stream returns an array or an object.
set
(
-
sum
-
[silent=false]
Set accumulated value.
split
(
-
splitterFn
Split maps one of several streams based on custom logic.
The function should return an EventEmitter.
Parameters:
-
splitterFn
FunctionSplitter function