Created
December 29, 2020 22:11
-
-
Save strager/7e0692e8cbe1f24d3046fafc22ab216e 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
from functools import singledispatchmethod | |
class Negator: | |
@singledispatchmethod | |
def neg(self, arg): | |
raise NotImplementedError("Cannot negate a") | |
@neg.register | |
def _(self, arg: int): | |
return -arg | |
@neg.register | |
def _(self, arg: bool): | |
return not arg | |
print(Negator().neg(100)) | |
print(Negator().neg(False)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment