source: utilitiespy/tudelft/utilities/tools/Iterator.py

Last change on this file was 1169, checked in by wouter, 4 weeks ago

#368 utilitiespy is now py.typed

File size: 596 bytes
Line 
1
2
3from collections.abc import Iterator
4from itertools import tee
5from typing import Tuple
6
7def 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
24def test(self)->None:
25 a:object = "a"
26 print(a)
27
Note: See TracBrowser for help on using the repository browser.