async def main(): in_ch = c.to_chan(range(4)) with self.assertRaises(TypeError): c.transduce( xf.filter(lambda x: x % 2 == 0), 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.transduce( xf.filter(lambda x: x % 2 == 0), xf.multi_arity(lambda: 100, xf.identity, lambda x, y: x + y), in_ch) self.assertEqual(await result_ch.get(), 102)
def test_xform_filter(self): ch = c.promise_chan(xf.filter(lambda x: x > 0)) self.assertIs(ch.b_put(-1), True) self.assertIs(ch.b_put(1), True) self.assertIs(ch.b_put(2), True) self.assertEqual(ch.b_get(), 1) self.assertEqual(ch.b_get(), 1)
def test_itransduce_init_only(self): result = xf.itransduce(xf.filter(None), xf.identity, 1, []) self.assertEqual(result, 1)
async def main(): ch = self.chan(1, xf.filter(lambda x: x % 2 == 0)) c.onto_chan(ch, [0, 1, 2]) self.assertEqual(await a_list(ch), [0, 2])
def test_itransduce_empty_no_init(self): result = xf.itransduce(xf.filter(lambda x: x % 2 == 0), sum_rf, []) self.assertEqual(result, 0)
def test_itransduce_empty_no_init_no_arity_zero(self): with self.assertRaises(TypeError): xf.itransduce(xf.filter(lambda x: x % 2 == 0), lambda x, y: x + y, [])
def test_itransduce_some(self): result = xf.itransduce(xf.filter(lambda x: x % 2 == 0), sum_rf, 1, [2, 3, 8]) self.assertEqual(result, 11)
def test_itransduce_some_no_init(self): result = xf.itransduce(xf.filter(lambda x: x % 2 == 0), sum_rf, [1, 2, 3, 8]) self.assertEqual(result, 10)
def test_complete(self): xform = xf.comp(xf.filter(lambda x: x % 2 == 0), xf.partition_all(2)) self.assertEqual(list(xf.xiter(xform, [2, 4, 5, 6])), [(2, 4), (6,)])
def test_arity_zero(self): self.assertEqual(xf.filter(None)(lambda: 'success')(), 'success')
def test_reduced(self): xform = xf.comp(xf.filter(lambda x: x % 2 == 0), xf.take(2)) self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4, 5, 6])), [2, 4])
def test_filter_none(self): xform = xf.filter(lambda x: x % 2 == 0) self.assertEqual(list(xf.xiter(xform, [])), [])
def test_filter_some(self): xform = xf.filter(lambda x: x % 2 == 0) self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4])), [2, 4])