Created
June 23, 2012 21:31
-
-
Save thomasballinger/2980096 to your computer and use it in GitHub Desktop.
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
# 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