Skip to content

Commit 430d346

Browse files
committed
Iterable duck types
1 parent a6607a7 commit 430d346

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,8 @@ class MySortable:
11011101
```
11021102

11031103
### Iterator
1104+
* **Next() should return next item or raise 'StopIteration'.**
1105+
* **Iter() should return 'self'.**
11041106
```python
11051107
class Counter:
11061108
def __init__(self):
@@ -1205,7 +1207,7 @@ class MyCollection:
12051207
```
12061208

12071209
### Sequence
1208-
* **Only required methods are len() and getitem().**
1210+
* **Only required methods are len() and getitem(), that should return an item at index or raise 'IndexError'.**
12091211
* **Iter() and contains() automatically work on any object that has getitem() defined.**
12101212
* **Reversed() automatically works on any object that has getitem() and len() defined.**
12111213
```python

index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,10 @@ <h3 id="sortable">Sortable</h3>
10341034
<span class="hljs-keyword">return</span> <span class="hljs-built_in">NotImplemented</span>
10351035
</code></pre>
10361036
<h3 id="iterator-1">Iterator</h3>
1037+
<ul>
1038+
<li><strong>Next() should return next item or raise 'StopIteration'.</strong></li>
1039+
<li><strong>Iter() should return 'self'.</strong></li>
1040+
</ul>
10371041
<pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Counter</span>:</span>
10381042
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self)</span>:</span>
10391043
self.i = <span class="hljs-number">0</span>
@@ -1120,7 +1124,7 @@ <h3 id="collection">Collection</h3>
11201124
</code></pre>
11211125
<h3 id="sequence">Sequence</h3>
11221126
<ul>
1123-
<li><strong>Only required methods are len() and getitem().</strong></li>
1127+
<li><strong>Only required methods are len() and getitem(), that should return an item at index or raise 'IndexError'.</strong></li>
11241128
<li><strong>Iter() and contains() automatically work on any object that has getitem() defined.</strong></li>
11251129
<li><strong>Reversed() automatically works on any object that has getitem() and len() defined.</strong></li>
11261130
</ul>

0 commit comments

Comments
 (0)