Example #1
0
 def test_chained_transducers(self):
     result = transduce(transducer=compose(mapping(lambda x: x * x),
                                           filtering(lambda x: x % 5 != 0),
                                           taking(6),
                                           dropping_while(lambda x: x < 15),
                                           distinct()),
                        reducer=appending(),
                        iterable=range(20))
     self.assertSequenceEqual(result, [16, 36, 49])
Example #2
0
 def test_chained_transducers(self):
     result = transduce(transducer=compose(
                       mapping(lambda x: x*x),
                       filtering(lambda x: x % 5 != 0),
                       taking(6),
                       dropping_while(lambda x: x < 15),
                       distinct()),
                   reducer=appending(),
                   iterable=range(20))
     self.assertSequenceEqual(result, [16, 36, 49])
Example #3
0
    def test_chained_transducers(self):
        result = transduce(transducer=compose(
                         mapping(lambda x: x*x),
                         filtering(lambda x: x % 5 != 0),
                         taking(6),
                         dropping_while(lambda x: x < 15),
                         distinct()),
                     iterable=range(20))

        expected = [16, 36, 49]
        for r, e in zip(result, expected):
            self.assertEqual(r, e)
Example #4
0
    def test_chained_transducers(self):
        result = transduce(
            transducer=compose(
                mapping(lambda x: x * x),
                filtering(lambda x: x % 5 != 0),
                taking(6),
                dropping_while(lambda x: x < 15),
                distinct(),
            ),
            iterable=range(20),
        )

        expected = [16, 36, 49]
        for r, e in zip(result, expected):
            self.assertEqual(r, e)
Example #5
0
 def test_taking_validation(self):
     with self.assertRaises(ValueError):
         transduce(transducer=taking(-3),
                   reducer=appending(),
                   iterable=[2, 4, 5, 8, 10])
Example #6
0
 def test_taking(self):
     result = transduce(transducer=taking(3),
                        reducer=appending(),
                        iterable=[2, 4, 5, 8, 10])
     self.assertListEqual(result, [2, 4, 5])
Example #7
0
 def test_taking_validation(self):
     with self.assertRaises(ValueError):
         transduce(transducer=taking(-3),
                   reducer=appending(),
                   iterable=[2, 4, 5, 8, 10])
Example #8
0
 def test_taking(self):
     result = transduce(transducer=taking(3),
                        reducer=appending(),
                        iterable=[2, 4, 5, 8, 10])
     self.assertListEqual(result, [2, 4, 5])