aboutsummaryrefslogtreecommitdiff
path: root/immutables/map.py
diff options
context:
space:
mode:
Diffstat (limited to 'immutables/map.py')
-rw-r--r--immutables/map.py43
1 files changed, 33 insertions, 10 deletions
diff --git a/immutables/map.py b/immutables/map.py
index 9884956..f498d38 100644
--- a/immutables/map.py
+++ b/immutables/map.py
@@ -391,20 +391,43 @@ class CollisionNode:
buf.append('{}{!r}: {!r}'.format(pad, key, val))
-class GenWrapper:
+class MapKeys:
- def __init__(self, count, gen):
- self.__count = count
- self.__gen = gen
+ def __init__(self, c, m):
+ self.__count = c
+ self.__root = m
+
+ def __len__(self):
+ return self.__count
+
+ def __iter__(self):
+ return iter(self.__root.keys())
+
+
+class MapValues:
+
+ def __init__(self, c, m):
+ self.__count = c
+ self.__root = m
def __len__(self):
return self.__count
def __iter__(self):
- return self
+ return iter(self.__root.values())
+
+
+class MapItems:
+
+ def __init__(self, c, m):
+ self.__count = c
+ self.__root = m
- def __next__(self):
- return next(self.__gen)
+ def __len__(self):
+ return self.__count
+
+ def __iter__(self):
+ return iter(self.__root.items())
class Map:
@@ -544,13 +567,13 @@ class Map:
yield from self.__root.keys()
def keys(self):
- return GenWrapper(self.__count, self.__root.keys())
+ return MapKeys(self.__count, self.__root)
def values(self):
- return GenWrapper(self.__count, self.__root.values())
+ return MapValues(self.__count, self.__root)
def items(self):
- return GenWrapper(self.__count, self.__root.items())
+ return MapItems(self.__count, self.__root)
def __hash__(self):
if self.__hash != -1: