eotransform.sinks.filtered.SinkFiltered
- class SinkFiltered(wrapped_sink: Sink[SinkT], predicate: Callable[[SinkT], bool])[source]
Bases:
Sink[SinkT]Allows to filter items for passing them to the wrapped sink. >>> class RecordingSink(Sink[int]): … def __init__(self): … self.record = [] … def __call__(self, x: int) -> None: … self.record.append(x) >>> wrapped_sink = RecordingSink() >>> filtered_sink = SinkFiltered(wrapped_sink, lambda x: x % 2 == 1) >>> for i in range(4): … filtered_sink(i) >>> wrapped_sink.record [1, 3]
- Parameters:
wrapped_sink – the sink the filtered items are passed to
predicate – callable which determines if an item is passed to the wrapped sink
Methods