Created
August 10, 2011 19:53
-
-
Save timothyekl/1137985 to your computer and use it in GitHub Desktop.
Singleton tuplization of a set wrapper class's elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FooIterator: | |
def __init__(self, underlyingIter): | |
self.underlying = underlyingIter | |
def __iter__(self): | |
return self | |
def next(self): | |
try: | |
return (self.underlying.next(),) | |
except StopIteration: | |
raise | |
class Foo: | |
def __init__(self, data): | |
self.data = set(data) | |
def __iter__(self): | |
return self.data.__iter__() | |
def tuplize(self): | |
return FooIterator(self.__iter__()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment