Created
September 9, 2011 08:38
-
-
Save codeinthehole/1205776 to your computer and use it in GitHub Desktop.
Lightweight subclassing using curry
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
def curry(f, *args, **kwargs): | |
def curried(*more_args, **more_kwargs): | |
return f(*(args+more_args), **dict(kwargs, **more_kwargs)) | |
return curried | |
class Person(object): | |
def __init__(self, name, gender): | |
self.name = name | |
self.gender = gender | |
# Lightweight subclasses | |
Man = curry(Person, gender="Male") | |
Woman = curry(Person, gender="Female") | |
husband = Man("Donald") | |
wife = Woman("Donalina") | |
print husband.name, wife.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment