Map

Definition

class broqer.op.Map(function: Callable[[Any], Any], *args, unpack: bool = False, **kwargs)[source]

Apply function(*args, value, **kwargs) to each emitted value.

Parameters:
  • function – function to be applied for each emit
  • *args – variable arguments to be used for calling function
  • unpack – value from emits will be unpacked (*value)
  • **kwargs – keyword arguments to be used for calling function

Usage

Apply function(*args, value, **kwargs) to each emitted value

Usage:

>>> from broqer import Subject, op
>>> s = Subject()
>>> mapped_publisher = s | op.Map(lambda v:v*2)
>>> _disposable = mapped_publisher | op.Sink(print)
>>> s.emit(1)
2
>>> s.emit(-1)
-2
>>> s.emit(0)
0
>>> _disposable.dispose()

Also possible with additional args and kwargs:

>>> import operator
>>> mapped_publisher = s | op.Map(operator.add, 3)
>>> _disposable = mapped_publisher | op.Sink(print)
>>> s.emit(100)
103
>>> _disposable.dispose()
>>> _disposable = s | op.Map(print, 'Output:') | op.Sink(print, 'EMITTED')
>>> s.emit(1)
Output: 1
EMITTED None