Last change
on this file since 847 was 667, checked in by wouter, 13 months ago |
added tools to utilities package to include tools for java2python translator
|
File size:
537 bytes
|
Line | |
---|
1 |
|
---|
2 |
|
---|
3 | from collections.abc import Iterator
|
---|
4 | from itertools import tee
|
---|
5 | from typing import Tuple
|
---|
6 |
|
---|
7 | def hasNext(it)->Tuple[bool, Iterator]:
|
---|
8 | '''
|
---|
9 | A support function to test hasNext for standard python iterators.
|
---|
10 | usage, assuming it is already created (eg it=iter([1,2,3]):
|
---|
11 | nx, it = hasNext(it)
|
---|
12 |
|
---|
13 | After the call, nx will be True iff it has a next value.
|
---|
14 | The new it will be in original state (we have to damage the original iterator)
|
---|
15 | '''
|
---|
16 |
|
---|
17 | it,it1=tee(it)
|
---|
18 | try:
|
---|
19 | next(it1)
|
---|
20 | return True, it
|
---|
21 | except:
|
---|
22 | return False, it
|
---|
23 | |
---|
Note:
See
TracBrowser
for help on using the repository browser.