From bf33efc2f042b057fae5e19dc3e80d250c9cf47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 19 Jul 2019 15:31:27 +0200 Subject: [PATCH] Iterable duck types --- README.md | 6 ++---- index.html | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cf6da00..9c4c3c8 100644 --- a/README.md +++ b/README.md @@ -1207,8 +1207,7 @@ class MyCollection: def __init__(self, a): self.a = a def __iter__(self): - for el in self.a: - yield el + return iter(self.a) def __contains__(self, el): return el in self.a def __len__(self): @@ -1224,8 +1223,7 @@ class MySequence: def __init__(self, a): self.a = a def __iter__(self): - for el in self.a: - yield el + return iter(self.a) def __contains__(self, el): return el in self.a def __len__(self): diff --git a/index.html b/index.html index eb94c8b..1d1bea8 100644 --- a/index.html +++ b/index.html @@ -1122,8 +1122,7 @@ lock = threading.RLock(); with lock: ... def __init__(self, a): self.a = a def __iter__(self): - for el in self.a: - yield el + return iter(self.a) def __contains__(self, el): return el in self.a def __len__(self): @@ -1139,8 +1138,7 @@ lock = threading.RLock(); with lock: ... def __init__(self, a): self.a = a def __iter__(self): - for el in self.a: - yield el + return iter(self.a) def __contains__(self, el): return el in self.a def __len__(self):