Filter

Definition

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

Filters values based on a predicate function :param predicate: function to evaluate the filtering :param *args: variable arguments to be used for evaluating predicate :param unpack: value from emits will be unpacked (*value) :param **kwargs: keyword arguments to be used for evaluating predicate

Usage

Filters values based on a predicate function

Usage:

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

Also possible with additional args and kwargs:

>>> import operator
>>> filtered_publisher = s | op.Filter(operator.and_, 0x01)
>>> _disposable = filtered_publisher | op.Sink(print)
>>> s.emit(100)
>>> s.emit(101)
101