A simple, programmable, eagerly-evaluated, pipeline specialised on ViewAST transformations similar to f :: State s => s ViewState x -> s ViewState y
| 41 | |
| 42 | # TODO - type this properly |
| 43 | class Pipeline(t.Generic[P_IN]): |
| 44 | """ |
| 45 | A simple, programmable, eagerly-evaluated, pipeline specialised on ViewAST transformations |
| 46 | similar to f :: State s => s ViewState x -> s ViewState y |
| 47 | """ |
| 48 | |
| 49 | # NOTE - toolz has an untyped function for this |
| 50 | |
| 51 | def __init__(self, s: ViewState, x: P_IN = None): |
| 52 | self._state = s |
| 53 | self._x = x |
| 54 | |
| 55 | def pipe(self, p: BaseProcessor[P_IN, P_OUT]) -> Pipeline[P_OUT]: |
| 56 | p.s = self._state |
| 57 | y = p.__call__(self._x) # need to call as positional args |
| 58 | self._state = p.s |
| 59 | return Pipeline(self._state, y) |
| 60 | |
| 61 | @property |
| 62 | def state(self) -> ViewState: |
| 63 | return self._state |
| 64 | |
| 65 | @property |
| 66 | def result(self) -> P_IN: |
| 67 | return self._x |
| 68 | |
| 69 | |
| 70 | def mk_null_pipe(blocks: Blocks) -> Pipeline[None]: |
no outgoing calls