zero.stream.Stream.data¶
-
Stream.data(n_items=None)[source]¶ Iterate over the loader.
Under the hood,
Stream.nextis called, hence,Stream.iterationchanges during iterations.- Parameters
n_items (Optional[Union[int, float]]) – how many items to produce. If
None, interpreted aslen(self.loader). Iffloat, must bemath.inf.- Raises
AssertionError – if
n_itemsis float, but notmath.infValueError – if
loaderis an iterator andn_itemsisNone
- Return type
Iterator
Examples
stream = Stream(range(5)) assert list(stream.data()) == [0, 1, 2, 3, 4] assert list(stream.data(3)) == [0, 1, 2] # stream doesn't "start over"! assert list(stream.data(3)) == [3, 4, 0] assert list(stream.data(1)) == [1] assert list(stream.data(2)) == [2, 3]
for x in stream.data(math.inf): ... if stream.iteration % frequency: ...