Browse Source

Iterable duck types

pull/36/head
Jure Šorn 5 years ago
parent
commit
430d346eaa
2 changed files with 8 additions and 2 deletions
  1. 4
      README.md
  2. 6
      index.html

4
README.md

@ -1101,6 +1101,8 @@ class MySortable:
```
### Iterator
* **Next() should return next item or raise 'StopIteration'.**
* **Iter() should return 'self'.**
```python
class Counter:
def __init__(self):
@ -1205,7 +1207,7 @@ class MyCollection:
```
### Sequence
* **Only required methods are len() and getitem().**
* **Only required methods are len() and getitem(), that should return an item at index or raise 'IndexError'.**
* **Iter() and contains() automatically work on any object that has getitem() defined.**
* **Reversed() automatically works on any object that has getitem() and len() defined.**
```python

6
index.html

@ -1034,6 +1034,10 @@ Z = dataclasses.make_dataclass(<span class="hljs-string">'Z'</span>, [<span clas
<span class="hljs-keyword">return</span> <span class="hljs-built_in">NotImplemented</span>
</code></pre>
<h3 id="iterator-1">Iterator</h3>
<ul>
<li><strong>Next() should return next item or raise 'StopIteration'.</strong></li>
<li><strong>Iter() should return 'self'.</strong></li>
</ul>
<pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Counter</span>:</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self)</span>:</span>
self.i = <span class="hljs-number">0</span>
@ -1120,7 +1124,7 @@ lock = threading.RLock(); <span class="hljs-keyword">with</span> lock: ...
</code></pre>
<h3 id="sequence">Sequence</h3>
<ul>
<li><strong>Only required methods are len() and getitem().</strong></li>
<li><strong>Only required methods are len() and getitem(), that should return an item at index or raise 'IndexError'.</strong></li>
<li><strong>Iter() and contains() automatically work on any object that has getitem() defined.</strong></li>
<li><strong>Reversed() automatically works on any object that has getitem() and len() defined.</strong></li>
</ul>

Loading…
Cancel
Save