Streams.SimpleStream Class
samsara/streams/SimpleStream.js:9
A SimpleStream wraps an EventHandler and provides convenience
methods of map
, filter
, split
, and pluck
to
transform one stream into another.
Constructor
Streams.SimpleStream
()
private
Example:
Methods
filter
-
filterFn
Filter converts the current stream into a new stream that only emits if the filter condition is satisfied. The filter function should return a Boolean value.
Parameters:
-
filterFn
FunctionFunction to filter event payload
Returns:
stream Filtered stream
map
-
mapperFn
Map converts the current stream into a new stream with a modified (mapped) data payload.
Parameters:
-
mapperFn
FunctionFunction to map event payload
Returns:
stream Mapped stream
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 object.
Returns:
stream Plucked stream
split
-
splitterFn
Split maps one of several streams based on custom logic. The splitter function should return an EventEmitter type.
Parameters:
-
splitterFn
FunctionSplitter function