~nch/glue

50333171e5b5973cdef9c6e8d045750a3a0936e6 — nc 1 year, 2 months ago ea3a590
WIP this seems(?) to be working
2 files changed, 20 insertions(+), 3 deletions(-)

M dataflow.py
M test_dataflow.py
M dataflow.py => dataflow.py +18 -1
@@ 9,6 9,10 @@ class _StreamHandle:
    def __iter__(self):
        return self

    @property
    def first(self):
        return self.stream.vals[0]

    def __next__(self):
        i = self.i
        self.i += 1 # stream advances...


@@ 26,6 30,15 @@ class _StreamHandle:
    def copy(self):
        return _StreamHandle(self.stream, self.i)

    def __add__(self, other):
        def addf(a, b):
            while True:
                yield next(a) + next(b)
        return stream(addf)(self, other)

    def where(self, **kwargs):
        pass # TODO

class _Stream:
    def __init__(self, f, *args):
        self.gen = f(*args)


@@ 63,6 76,10 @@ def fby(x, y):
        yield y

@stream
def next_(s):
def var(name):
    pass

@stream
def next_(s): # TODO test
    while True:
        yield next(s)

M test_dataflow.py => test_dataflow.py +2 -2
@@ 38,9 38,9 @@ class TestDataflow2(unittest.TestCase):
        self.assertEqual(next(s), 2)

    def test_fby3(self):
        s = fby(int_(1), fby(int_(2), int_(3)))
        s = fby(int_(1), fby(int_(2) + int_(2), int_(3)))
        self.assertEqual(next(s), 1)
        self.assertEqual(next(s), 2)
        self.assertEqual(next(s), 4)
        self.assertEqual(next(s), 3)
        self.assertEqual(next(s), 3)