zero.stream.Stream.data¶
-
Stream.
data
(n_items=None)[source]¶ Iterate over the loader.
Under the hood,
Stream.next
is called, hence,Stream.iteration
changes 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_items
is float, but notmath.inf
ValueError – if
loader
is an iterator andn_items
isNone
- 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: ...