Adding tee & filters

This commit is contained in:
Zoe Roux
2020-11-07 21:36:06 +01:00
parent 5cf74f43dc
commit 25585be872
3 changed files with 33 additions and 1 deletions
+2 -1
View File
@@ -18,8 +18,9 @@ class Pipe(ABC):
def name(self):
raise NotImplementedError
@abstractmethod
def pipe(self, data: APData) -> APData:
pass
raise NotImplementedError
class Input(ABC):
+15
View File
@@ -0,0 +1,15 @@
from typing import Callable
from models import Pipe, APData
class FilterPipe(Pipe):
def __init__(self, filter: Callable[[APData], bool]):
super().__init__()
self.filter = filter
@property
def name(self):
return "Filter"
def pipe(self, data: APData) -> APData:
return data if self.filter(data) else None
+16
View File
@@ -0,0 +1,16 @@
from models import Pipe, APData
class TeePipe(Pipe):
def __init__(self, *outputs):
super().__init__()
self.outputs = outputs
@property
def name(self):
return "Tee"
def pipe(self, data: APData) -> APData:
for output in self.outputs:
output.pipe(data)
return data