Last active
October 22, 2022 13:57
-
-
Save ltbringer/4282915b687deea8d7fad08b3d06c356 to your computer and use it in GitHub Desktop.
Function composition with operator overloading
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
| from typing import Any, Callable | |
| a1 = Callable[[Any], Any] | |
| class Compose: | |
| def __init__(self, f: a1) -> None: | |
| self.f = f | |
| def __mul__(self, g: a1) -> a1: | |
| return Compose(lambda x: self.f(g(x))) | |
| def __call__(self, *args: Any, **kwds: Any) -> Any: | |
| return self.f(*args, **kwds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment