Example #1
0
    def test_chained_transducers(self):
        input = [0.0, 0.2, 0.8, 0.9, 1.1, 2.3, 2.6, 3.0, 4.1]
        output = CollectingSink()

        iterable_source(iterable=input,
                        target=transduce(
                            compose(pairwise(),
                                    mapping(lambda p: p[1] - p[0]),
                                    filtering(lambda d: d < 0.5),
                                    mapping(lambda _: "double-click")),
                            target=output()))

        result = list(output)
        self.assertListEqual(result, ['double-click', 'double-click', 'double-click', 'double-click', 'double-click'])
Example #2
0
    def test_chained_transducers(self):
        input = [0.0, 0.2, 0.8, 0.9, 1.1, 2.3, 2.6, 3.0, 4.1]
        output = CollectingSink()

        iterable_source(iterable=input,
                        target=transduce(compose(
                            pairwise(), mapping(lambda p: p[1] - p[0]),
                            filtering(lambda d: d < 0.5),
                            mapping(lambda _: "double-click")),
                                         target=output()))

        result = list(output)
        self.assertListEqual(result, [
            'double-click', 'double-click', 'double-click', 'double-click',
            'double-click'
        ])
Example #3
0
 def test_pairwise_single(self):
     """A single item fed into pairwise is discarded."""
     result = transduce(transducer=pairwise(),
                        reducer=appending(),
                        iterable=[42])
     self.assertListEqual(result, [])
Example #4
0
 def test_pairwise_at_least_two(self):
     result = transduce(transducer=pairwise(),
                        reducer=appending(),
                        iterable=[1, 3, 5, 7, 2, 1, 9])
     self.assertListEqual(result, [(1, 3), (3, 5), (5, 7), (7, 2), (2, 1),
                                   (1, 9)])
Example #5
0
 def test_pairwise_single(self):
     """A single item fed into pairwise is discarded."""
     result = transduce(transducer=pairwise(),
                        reducer=appending(),
                        iterable=[42])
     self.assertListEqual(result, [])
Example #6
0
 def test_pairwise_at_least_two(self):
     result = transduce(transducer=pairwise(),
                        reducer=appending(),
                        iterable=[1, 3, 5, 7, 2, 1, 9])
     self.assertListEqual(result, [(1, 3), (3, 5), (5, 7), (7, 2), (2, 1), (1, 9)])