當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。