Map

Definition

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

Map object applied to publisher

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 Value, op, Sink
>>> s = Value()
>>> mapped_publisher = s | op.Map(lambda v:v*2)
>>> _disposable = mapped_publisher.subscribe(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.subscribe(Sink(print))
3
>>> s.emit(100)
103
>>> _disposable.dispose()
>>> _disposable = (s | op.Map(print, 'Output:')).subscribe(                                                Sink(print, 'EMITTED'))
Output: 100
EMITTED None
>>> s.emit(1)
Output: 1
EMITTED None