Last active
August 6, 2021 08:19
-
-
Save 4e1e0603/dd25a5427de454e2b55e459985832ef7 to your computer and use it in GitHub Desktop.
Comment for Functional Python Article
This file contains hidden or 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
# Functional composition with `>>` operator. | |
class Value: | |
def __init__(self, value) -> None: | |
self.value = value | |
def __rshift__(self, that): | |
print(f"{that.__name__}({self.value})") | |
return Value(that(self.value)) | |
def __call__(self): | |
return self.value | |
Value(x) >> f >> g >> h >> print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment