Exemplo n.º 1
0
 def test_windowing_no_padding(self):
     result = transduce(transducer=windowing(3, window_type=list),
                        reducer=appending(),
                        iterable=[42, 12, 45, 9, 18, 3, 34, 13])
     self.assertListEqual(
         result, [[42], [42, 12], [42, 12, 45], [12, 45, 9], [45, 9, 18],
                  [9, 18, 3], [18, 3, 34], [3, 34, 13], [34, 13], [13]])
Exemplo n.º 2
0
 def test_windowing_padding(self):
     result = transduce(transducer=windowing(3, padding=0, window_type=list),
                        reducer=appending(),
                        iterable=[42, 12, 45, 9, 18, 3, 34, 13])
     self.assertListEqual(result,
                          [[0, 0, 42],
                           [0, 42, 12],
                           [42, 12, 45],
                           [12, 45, 9],
                           [45, 9, 18],
                           [9, 18, 3],
                           [18, 3, 34],
                           [3, 34, 13],
                           [34, 13, 0],
                           [13, 0, 0]])
Exemplo n.º 3
0
async def counter(delay, to):
    # from transducer.coop import transduce
    # from transducer.reducers import effecting
    # await transduce(
    #     transducer=compose(
    #         enumerating(),
    #         windowing(3)
    #     ),
    #     reducer=effecting(print),
    #     aiterable=ticker(delay, to)
    # )

    from transducer.lazy_coop import transduce
    async for item in transduce(transducer=compose(enumerating(),
                                                   windowing(3)),
                                aiterable=ticker(delay, to)):
        print(item)
Exemplo n.º 4
0
 def test_windowing_validation(self):
     with self.assertRaises(ValueError):
         transduce(transducer=windowing(0),
                   reducer=appending(),
                   iterable=[42, 12, 45, 9, 18, 3, 34, 13])
Exemplo n.º 5
0
 def test_windowing_validation(self):
     with self.assertRaises(ValueError):
         transduce(transducer=windowing(0),
                   reducer=appending(),
                   iterable=[42, 12, 45, 9, 18, 3, 34, 13])