Last change
on this file since 234 was 195, checked in by wouter, 4 years ago |
preparing python version of immutablelist
|
File size:
722 bytes
|
Line | |
---|
1 | from decimal import Decimal
|
---|
2 | from typing import TypeVar
|
---|
3 |
|
---|
4 | from immutablelist.ImmutableList import ImmutableList
|
---|
5 |
|
---|
6 |
|
---|
7 | E = TypeVar('E')
|
---|
8 | class 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 |
|
---|
23 | class AbstractImmutableList(ImmutableList[E]):
|
---|
24 | def __iter__(self):
|
---|
25 | return ItemIterator(self) |
---|
Note:
See
TracBrowser
for help on using the repository browser.