Created
July 26, 2020 02:24
-
-
Save JakeTheCorn/415141fdb69e3eb114934518a29f48d1 to your computer and use it in GitHub Desktop.
An idea I had to code comparisons... The idea is that you can't "have" a comparison without two things to compare, a, b... so it could go in a constructor. This could also be useful as a template method pattern.
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 Comparison: | |
def __init__(self, a, b, **kwargs): | |
self.a = a | |
self.b = b | |
self.kwargs = kwargs | |
def compare(self): | |
""" .compare() -> Union[1, -1, 0]""" | |
if self._a_has_higher_precedence(): | |
return 1 | |
if self._a_has_equal_precedence(): | |
return 0 | |
if self._a_has_lower_precedence(): | |
return -1 | |
return 0. # or raise? | |
def _a_has_higher_precedence(self): | |
pass | |
def _a_has_lower_precedence(self): | |
pass | |
def _a_has_equal_precedence(self): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment