当前位置: 首页>>代码示例>>Python>>正文


Python eager.transduce函数代码示例

本文整理汇总了Python中transducer.eager.transduce函数的典型用法代码示例。如果您正苦于以下问题:Python transduce函数的具体用法?Python transduce怎么用?Python transduce使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了transduce函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_zero_items_returns_initial_empty_collection

    def test_zero_items_returns_initial_empty_collection(self):
        collection = CollectingSink()

        transduce(Transducer,
                  sending(),
                  empty_iter(),
                  init=collection())

        self.assertEqual(len(collection), 0)
开发者ID:dlobue,项目名称:python-transducers,代码行数:9,代码来源:test_reducers.py

示例2: test_two_items_returns_two_element_list

    def test_two_items_returns_two_element_list(self):
        collection = CollectingSink()

        transduce(Transducer,
                  sending(),
                  [23, 78],
                  init=collection())

        self.assertEqual(list(collection), [23, 78])
开发者ID:dlobue,项目名称:python-transducers,代码行数:9,代码来源:test_reducers.py

示例3: test_two_items_causes_completion

    def test_two_items_causes_completion(self):
        singular_sink = SingularSink()

        transduce(Transducer,
                  sending(),
                  [23, 78],
                  init=singular_sink())

        self.assertTrue(singular_sink.has_value)
开发者ID:dlobue,项目名称:python-transducers,代码行数:9,代码来源:test_reducers.py

示例4: test_ordering_preserves_mutable_sequence_type

 def test_ordering_preserves_mutable_sequence_type(self):
     result = transduce(transducer=ordering(),
                        reducer=appending(),
                        iterable=[4, 2, 6, 10, 8],
                        init=deque())
     self.assertIsInstance(result, deque)
     self.assertSequenceEqual(result, deque([2, 4, 6, 8, 10]))
开发者ID:dlobue,项目名称:python-transducers,代码行数:7,代码来源:test_eager.py

示例5: test_chained_transducers

 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])
开发者ID:dlobue,项目名称:python-transducers,代码行数:10,代码来源:test_eager.py

示例6: test_completing_with_summing_zero_items_returns_identity

    def test_completing_with_summing_zero_items_returns_identity(self):

        def add(a, b):
            return a + b

        summing = completing(add, identity=0)

        result = transduce(Transducer,
                           summing,
                           [])
        self.assertEqual(result, 0)
开发者ID:dlobue,项目名称:python-transducers,代码行数:11,代码来源:test_reducers.py

示例7: test_completing_with_summing_four_items

    def test_completing_with_summing_four_items(self):

        def add(a, b):
            return a + b

        summing = completing(add, identity=0)

        result = transduce(Transducer,
                           summing,
                           [4, 2, 1, 9])
        self.assertEqual(result, 16)
开发者ID:dlobue,项目名称:python-transducers,代码行数:11,代码来源:test_reducers.py

示例8: test_completing_with_multiplying_zero_items_returns_identity

    def test_completing_with_multiplying_zero_items_returns_identity(self):

        def multiply(a, b):
            return a * b

        multiplying = completing(multiply, identity=1)

        result = transduce(Transducer,
                           multiplying,
                           [])
        self.assertEqual(result, 1)
开发者ID:dlobue,项目名称:python-transducers,代码行数:11,代码来源:test_reducers.py

示例9: test_completing_with_multiplying_four_items

    def test_completing_with_multiplying_four_items(self):

        def multiply(a, b):
            return a * b

        multiplying = completing(multiply, identity=1)

        result = transduce(Transducer,
                           multiplying,
                           [4, 2, 1, 9])
        self.assertEqual(result, 72)
开发者ID:dlobue,项目名称:python-transducers,代码行数:11,代码来源:test_reducers.py

示例10: test_windowing_padding

 def test_windowing_padding(self):
     result = transduce(transducer=windowing(3, padding=0, window_type=list),
                        reducer=appending(),
                        iterable=[42, 12, 45, 9, 18, 3, 34, 13])
     self.assertListEqual(result,
                          [[0, 0, 42],
                           [0, 42, 12],
                           [42, 12, 45],
                           [12, 45, 9],
                           [45, 9, 18],
                           [9, 18, 3],
                           [18, 3, 34],
                           [3, 34, 13],
                           [34, 13, 0],
                           [13, 0, 0]])
开发者ID:dlobue,项目名称:python-transducers,代码行数:15,代码来源:test_eager.py

示例11: test_zero_items_returns_initial_empty_set

 def test_zero_items_returns_initial_empty_set(self):
     result = transduce(Transducer,
                        adding(),
                        empty_iter())
     self.assertEqual(result, set())
开发者ID:dlobue,项目名称:python-transducers,代码行数:5,代码来源:test_reducers.py

示例12: test_conjoining_to_non_sequence_raises_type_error

 def test_conjoining_to_non_sequence_raises_type_error(self):
     with self.assertRaises(TypeError):
         transduce(Transducer,
                   conjoining(),
                   (23, 78),
                   init=set())
开发者ID:dlobue,项目名称:python-transducers,代码行数:6,代码来源:test_reducers.py

示例13: test_conjoining_preserves_initial_sequence_type

 def test_conjoining_preserves_initial_sequence_type(self):
     result = transduce(Transducer,
                        conjoining(),
                        (23, 78),
                        init=[])
     self.assertEqual(result, [23, 78])
开发者ID:dlobue,项目名称:python-transducers,代码行数:6,代码来源:test_reducers.py

示例14: test_zero_items_returns_initial_empty_tuple

 def test_zero_items_returns_initial_empty_tuple(self):
     result = transduce(Transducer,
                        conjoining(),
                        empty_iter())
     self.assertEqual(result, tuple())
开发者ID:dlobue,项目名称:python-transducers,代码行数:5,代码来源:test_reducers.py

示例15: test_two_items_returns_two_element_tuple

 def test_two_items_returns_two_element_tuple(self):
     result = transduce(Transducer,
                        conjoining(),
                        [23, 78])
     self.assertEqual(result, (23, 78))
开发者ID:dlobue,项目名称:python-transducers,代码行数:5,代码来源:test_reducers.py


注:本文中的transducer.eager.transduce函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。