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)
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)
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)
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)
async def main(): ch = chan() ch.close() result_ch = c.reduce(lambda: None, 'init', ch) self.assertEqual(await result_ch.get(), 'init')