source: immutablelistpy/immutablelist/AbstractImmutableList.py@ 209

Last change on this file since 209 was 195, checked in by wouter, 3 years ago

preparing python version of immutablelist

File size: 722 bytes
Line 
1from decimal import Decimal
2from typing import TypeVar
3
4from immutablelist.ImmutableList import ImmutableList
5
6
7E = TypeVar('E')
8class ItemIterator:
9 def __init__(self, l:ImmutableList[E]):
10 # Team object reference
11 self._l = l
12 # member variable to keep track of current index
13 self._index = Decimal(0)
14 def __next__(self):
15 '''Returns the next value from team object's lists '''
16 if self._index >= self._l.size():
17 # End of Iteration
18 raise StopIteration
19 val=self._l.get(self._index)
20 self._index += Decimal(1)
21 return val
22
23class AbstractImmutableList(ImmutableList[E]):
24 def __iter__(self):
25 return ItemIterator(self)
Note: See TracBrowser for help on using the repository browser.