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 as len(self.loader). If float, must be math.inf.

Raises
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:
        ...