Пример #1
0
 async def main():
     in_ch = chan()
     in_ch.close()
     result_ch = c.reduce(
         xf.multi_arity(lambda: 100, xf.identity, lambda x, y: x + y),
         in_ch)
     self.assertEqual(await result_ch.get(), 100)
Пример #2
0
        async def main():
            in_ch = c.to_chan(range(4))

            def rf(result, val):
                if val == 2:
                    return xf.reduced(result + 2)
                return result + val

            result_ch = c.reduce(rf, 100, in_ch)
            self.assertEqual(await result_ch.get(), 103)
Пример #3
0
 async def main():
     in_ch = c.to_chan(range(4))
     with self.assertRaises(TypeError):
         c.reduce(xf.multi_arity(None, xf.identity, lambda x, y: x + y),
                  in_ch)
Пример #4
0
 async def main():
     in_ch = c.to_chan(range(4))
     result_ch = c.reduce(lambda x, y: x + y, 100, in_ch)
     self.assertEqual(await result_ch.get(), 106)
Пример #5
0
 async def main():
     ch = chan()
     ch.close()
     result_ch = c.reduce(lambda: None, 'init', ch)
     self.assertEqual(await result_ch.get(), 'init')