Extend .slice() method implementation to all Iterables
Change-Id: I599019ea11a59798d131236e89ee57097b8c196e Closes-bug: #1587509
This commit is contained in:
parent
d01a78cc7b
commit
9a5c03a90c
|
@ -452,6 +452,7 @@ def last_index_where(collection, predicate):
|
|||
@specs.parameter('length', int)
|
||||
@specs.inject('to_list', yaqltypes.Delegate('to_list', method=True))
|
||||
def slice_(collection, length, to_list):
|
||||
collection = iter(collection)
|
||||
while True:
|
||||
res = to_list(itertools.islice(collection, length))
|
||||
if res:
|
||||
|
|
|
@ -300,6 +300,9 @@ class TestQueries(yaql.tests.TestCase):
|
|||
self.assertEqual(
|
||||
[[1, 2], [3, 4], [5]],
|
||||
self.eval('range(1, 6).slice(2)'))
|
||||
self.assertEqual(
|
||||
[[1, 2], [3, 4], [5]],
|
||||
self.eval('[1,2,3,4,5].slice(2)'))
|
||||
|
||||
def test_split(self):
|
||||
self.assertEqual(
|
||||
|
|
Loading…
Reference in New Issue