diff options
| author | Scott Gasch <[email protected]> | 2022-07-05 11:25:35 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2022-07-05 11:25:35 -0700 |
| commit | d54d91ddfb14821ce1e1d878a96faec090ff31b9 (patch) | |
| tree | 2fcc20cc02fdf50023b144df8bd587fa3a00bdcc /iter_utils.py | |
| parent | 53d8e09eb7aded181479fda535349b4583e49d3f (diff) | |
Update docs.
Diffstat (limited to 'iter_utils.py')
| -rw-r--r-- | iter_utils.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/iter_utils.py b/iter_utils.py index b1a137c..85c2749 100644 --- a/iter_utils.py +++ b/iter_utils.py @@ -1,14 +1,25 @@ #!/usr/bin/env python3 +# © Copyright 2021-2022, Scott Gasch + +"""A collection if :class:`Iterator` subclasses that can be composed +with another iterator and provide extra functionality. e.g. + + + :class:`PeekingIterator` + + :class:`PushbackIterator` + + :class:`SamplingIterator` + +""" + import random from collections.abc import Iterator from typing import Any, List, Optional class PeekingIterator(Iterator): - """An iterator that lets you peek() at the next item on deck. - Returns None when there is no next item (i.e. when __next__() - will produce a StopIteration exception). + """An iterator that lets you :method:`peek` at the next item on deck. + Returns None when there is no next item (i.e. when + :method:`__next__` will produce a StopIteration exception). >>> p = PeekingIterator(iter(range(3))) >>> p.__next__() @@ -27,6 +38,7 @@ class PeekingIterator(Iterator): Traceback (most recent call last): ... StopIteration + """ def __init__(self, source_iter: Iterator): @@ -88,7 +100,7 @@ class PushbackIterator(Iterator): return self def __next__(self) -> Any: - if len(self.pushed_back): + if len(self.pushed_back) > 0: return self.pushed_back.pop() return self.source_iter.__next__() |
