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


Python Stream.range方法代码示例

本文整理汇总了Python中streams.Stream.range方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.range方法的具体用法?Python Stream.range怎么用?Python Stream.range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在streams.Stream的用法示例。


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

示例1: test_it_should_concatenate_iterables

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
    def test_it_should_concatenate_iterables(self):
        stream = Stream.concat(Stream.range(10), Stream.range(10))
        self.assertListEqual(list(stream), list(xrange(10)) + list(xrange(10)))

        stream = Stream.concat(xrange(10), xrange(10), xrange(10))
        self.assertListEqual(list(stream.distinct()), list(xrange(10)))

        stream = Stream.concat(xrange(10), xrange(10), xrange(10))
        self.assertEqual(stream.count(), 30)
开发者ID:9seconds,项目名称:streams,代码行数:11,代码来源:test_stream.py

示例2: test_no_cache

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_no_cache(self):
     # Make a normal stream.
     stream = Stream.range(10)
     # Iterate once
     self.assertEqual(list(stream), list(range(10)))
     # Iterate twice
     self.assertEqual(list(stream), [])
开发者ID:9seconds,项目名称:streams,代码行数:9,代码来源:test_stream.py

示例3: test_cache

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
    def test_cache(self):
        # Make a cached stream.
        stream = Stream.range(10).cache()
        # Iterate once
        self.assertEqual(list(stream), list(range(10)))
        # Iterate twice, this time from the cache.
        self.assertEqual(list(stream), list(range(10)))

        # Now, we make a new, smaller, cached stream fromm our cached stream.
        stream = stream.cache(5)
        # Iterate once
        self.assertEqual(list(stream), list(range(10)))
        # Iterate twice, this time from the cache. We get the last 5 values.
        self.assertEqual(list(stream), list(range(5, 10)))
开发者ID:9seconds,项目名称:streams,代码行数:16,代码来源:test_stream.py

示例4: test_it_should_iterate_over_an_iterable_multiple_times

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_it_should_iterate_over_an_iterable_multiple_times(self):
     stream = Stream.range(10)
     self.assertListEqual(list(stream), list(xrange(10)))
     self.assertListEqual(list(stream), [])
开发者ID:9seconds,项目名称:streams,代码行数:6,代码来源:test_stream.py

示例5: test_it_should_produce_a_range

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_it_should_produce_a_range(self):
     stream = Stream.range(10)
     self.assertIsInstance(stream, Stream)
     self.assertEqual(list(stream), list(range(10)))
开发者ID:9seconds,项目名称:streams,代码行数:6,代码来源:test_stream.py

示例6: test_it_should_map_a_predicate_to_values_in_key_value_pairs

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_it_should_map_a_predicate_to_values_in_key_value_pairs(self):
     stream = Stream.range(10).tuplify()
     mapped = stream.value_map(lambda v: v ** 2)
     self.assertListEqual(list(mapped), [(x, x ** 2) for x in xrange(10)])
开发者ID:9seconds,项目名称:streams,代码行数:6,代码来源:test_stream.py

示例7: test_it_should_expand_a_stream_to_tuples

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
    def test_it_should_expand_a_stream_to_tuples(self):
        tuples = Stream.range(10).tuplify()
        self.assertListEqual(list(tuples), [(i, i) for i in range(10)])

        tuples = Stream.range(10).tuplify(clones=4)
        self.assertListEqual(list(tuples), [(i, i, i, i) for i in range(10)])
开发者ID:9seconds,项目名称:streams,代码行数:8,代码来源:test_stream.py

示例8: test_it_should_reverse_sort_the_stream

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_it_should_reverse_sort_the_stream(self):
     stream = Stream.range(10)
     sorted = stream.sorted(reverse=True)
     self.assertListEqual(list(sorted), list(reversed(range(10))))
开发者ID:9seconds,项目名称:streams,代码行数:6,代码来源:test_stream.py

示例9: test_reversed_should_reverse_the_stream

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_reversed_should_reverse_the_stream(self):
     stream = Stream.range(10)
     reverse = reversed(stream)
     self.assertListEqual(list(reverse), list(reversed(range(10))))
开发者ID:9seconds,项目名称:streams,代码行数:6,代码来源:test_stream.py

示例10: test_it_should_reduce_the_stream

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_it_should_reduce_the_stream(self):
     stream = Stream.range(10)
     reduced = stream.reduce(add)
     self.assertEqual(reduced, sum(range(10)))
开发者ID:9seconds,项目名称:streams,代码行数:6,代码来源:test_stream.py

示例11: test_range

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_range(self):
     self.assertListEqual(list(Stream.range(100)), list(xrange(100)))
开发者ID:9seconds,项目名称:streams,代码行数:4,代码来源:test_stream.py

示例12: test_it_should_apply_a_side_effect_to_the_stream

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_it_should_apply_a_side_effect_to_the_stream(self):
     side_list = []
     stream = Stream.range(10)
     self.assertEqual(side_list, list(stream.peek(side_list.append)))
开发者ID:9seconds,项目名称:streams,代码行数:6,代码来源:test_stream.py

示例13: test_it_should_return_the_first_element_without_consuming_it

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_it_should_return_the_first_element_without_consuming_it(self):
     stream = Stream.range(10)
     self.assertEqual(stream.first, 0)
     self.assertEqual(stream.first, 0)
     self.assertEqual(stream.first, 0)
     self.assertListEqual(list(stream), list(xrange(10)))
开发者ID:9seconds,项目名称:streams,代码行数:8,代码来源:test_stream.py

示例14: test_it_should_exclude_items

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_it_should_exclude_items(self):
     stream = Stream.range(10)
     odds = stream.exclude(lambda x: x % 2)
     self.assertListEqual(list(odds), [1, 3, 5, 7, 9])
开发者ID:9seconds,项目名称:streams,代码行数:6,代码来源:test_stream.py

示例15: test_it_should_count_the_number_of_items_in_the_stream

# 需要导入模块: from streams import Stream [as 别名]
# 或者: from streams.Stream import range [as 别名]
 def test_it_should_count_the_number_of_items_in_the_stream(self):
     stream = Stream.range(100)
     self.assertEqual(stream.count(), 100)
开发者ID:9seconds,项目名称:streams,代码行数:5,代码来源:test_stream.py


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