mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 02:49:27 +01:00
Added utils.iter.one, to grab one value from an iterable.
This commit is contained in:
parent
201d4acd26
commit
b369039507
@ -148,6 +148,11 @@ def ilen(iterable):
|
||||
i += 1
|
||||
return i
|
||||
|
||||
def one(iterable):
|
||||
for x in iterable:
|
||||
return x
|
||||
raise ValueError, 'Empty iterable: %r' % iterable
|
||||
|
||||
def startswith(long, short):
|
||||
longI = iter(long)
|
||||
shortI = iter(short)
|
||||
|
@ -384,6 +384,14 @@ class StrTest(SupyTestCase):
|
||||
|
||||
|
||||
class IterTest(SupyTestCase):
|
||||
def testOne(self):
|
||||
L = range(3)
|
||||
i = iter(L)
|
||||
self.assertEqual(utils.iter.one(i), 0)
|
||||
self.assertEqual(utils.iter.one(i), 1)
|
||||
self.assertEqual(utils.iter.one(i), 2)
|
||||
self.assertRaises(ValueError, utils.iter.one, i)
|
||||
|
||||
def testLimited(self):
|
||||
L = range(10)
|
||||
self.assertEqual([], list(utils.iter.limited(L, 0)))
|
||||
|
Loading…
Reference in New Issue
Block a user