Skip to content

Instantly share code, notes, and snippets.

@thomasballinger
Created June 23, 2012 21:31
Show Gist options
  • Save thomasballinger/2980096 to your computer and use it in GitHub Desktop.
Save thomasballinger/2980096 to your computer and use it in GitHub Desktop.
# TODO: make mix-in functions return objects of the same type?
# Whatever objects they would return, but with the mix-in mixed in?
class enumerable(object):
def filter(self, f):
return filter(f, self)
def map(self, f):
return map(f, self)
def foreach(self, f):
return [f(x) for x in self]
class rudict(dict, enumerable):
pass
class rulist(dict, enumerable):
def __init__(self, enum):
for x in enum:
self.append(x)
if __name__ == '__main__':
x = rudict()
x['a'] = 3
x['b'] = 4
x['c'] = 5
x['d'] = 6
print x
print x.filter(lambda x: x>'b')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment