本文整理匯總了Python中streampy.Stream類的典型用法代碼示例。如果您正苦於以下問題:Python Stream類的具體用法?Python Stream怎麽用?Python Stream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Stream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_simple_3
def test_simple_3(self):
element = Stream.range(100000) \
.filter(lambda x: x % 2 == 0) \
.map(lambda x: str(x)) \
.map(lambda x: 'Hi{0}'.format(x)) \
.map(lambda x: x.upper()) \
.filter(lambda x: x.endswith('8')) \
.limit(10) \
.map(lambda x: x[2]) \
.skip(1) \
.map(int) \
.list()
self.assertEquals(element, list(range(1, 10)))
示例2: test_create_stream_with_list_params
def test_create_stream_with_list_params(self):
s = Stream([])
self.assertEquals(0, s.size())
s = Stream([1])
self.assertEquals(1, s.size())
示例3: test_simple_map_1
def test_simple_map_1(self):
def add(x, y):
return x + y
s = Stream.range(10000).map(lambda x: x * 2).reduce(add, initializer=0)
self.assertEquals(s, 99990000)
示例4: test_simple_exclude_3
def test_simple_exclude_3(self):
s = Stream.range(100001).exclude(lambda x: x > 50000)
self.assertEquals(50001, s.size())
示例5: test_simple_filter_3
def test_simple_filter_3(self):
s = Stream.range(100001).filter(lambda x: x > 50000)
self.assertEquals(50000, s.size())
示例6: test_simple_size_3
def test_simple_size_3(self):
s = Stream("azertyuiop").filter(lambda x: x == 'a')
self.assertEquals(s.size(), 1)
示例7: test_simple_size_1
def test_simple_size_1(self):
self.assertEquals(Stream.range(999).size(), 999)
示例8: test_simple_last_3
def test_simple_last_3(self):
self.assertEquals(Stream.range(423).last(predicate=lambda x: 42 < x < 46), 45)
示例9: test_simple_last_1
def test_simple_last_1(self):
self.assertEquals(Stream.range(10).last(), 9)
示例10: test_simple_last_2
def test_simple_last_2(self):
self.assertEquals(Stream.range(10).last(predicate=lambda x: x > 1), 9)
示例11: test_create_stream_with_generator_params
def test_create_stream_with_generator_params(self):
s = Stream.range(1000)
self.assertEquals(1000, s.size())
示例12: test_simple_first_1
def test_simple_first_1(self):
self.assertEquals(Stream.range(10).first(), 0)
示例13: test_simple_range_2
def test_simple_range_2(self):
self.assertEquals(Stream.range(42000).list(), list(range(42000)))
示例14: test_simple_chunk_2
def test_simple_chunk_2(self):
self.assertEqual(Stream.range(10).chunk(3).list(), [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]])
示例15: test_simple_skip_1
def test_simple_skip_1(self):
self.assertEquals(Stream.range(10).skip(9).list(), [9])