Last active
September 4, 2022 22:24
-
-
Save theteachr/b3bbe6b180b6a6af19feb5b7988d29c6 to your computer and use it in GitHub Desktop.
Revisions
-
theteachr revised this gist
Sep 4, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -54,8 +54,8 @@ def main(): print(square << 2) # 4 print(square . inc << 2) # 9 print(inc . square << 2) # 5 print(inc . inc . square . inc << 2) # 11 print((inc . inc . square . inc * 2) << 2) # 146 print((inc * 4) << 2) # 6 print(2 >> inc) # 3 print([8, 2] >> (curried_map << square)) -
theteachr revised this gist
Sep 4, 2022 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,10 +4,10 @@ def __init__(self, f): def __lshift__(self, rhs): return self.f(rhs) def __rrshift__(self, lhs): return self.f(lhs) def __getattr__(self, f): @BitShiftFunc def composed(x): @@ -52,8 +52,8 @@ def main(): print(BitShiftFunc(len) << 'Hello') # 5 print(square(2)) # 4 print(square << 2) # 4 print(square . inc << 2) # 9 print(inc . square << 2) # 5 print(inc.inc.square.inc << 2) # 11 print((inc.inc.square.inc * 2) << 2) # 146 print((inc * 4) << 2) # 6 -
theteachr revised this gist
Sep 4, 2022 . 1 changed file with 6 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,13 @@ class BitShiftFunc: def __init__(self, f): self.f = f def __lshift__(self, rhs): return self.f(rhs) def __rrshift__(self, lhs): return self.f(lhs) def __getattr__(self, f): @BitShiftFunc def composed(x): @@ -48,7 +44,7 @@ def cube(x): @BitShiftFunc def curried_map(f): return BitShiftFunc(lambda lst: list(map(f, lst))) def main(): @@ -61,8 +57,8 @@ def main(): print(inc.inc.square.inc << 2) # 11 print((inc.inc.square.inc * 2) << 2) # 146 print((inc * 4) << 2) # 6 print(2 >> inc) # 3 print([8, 2] >> (curried_map << square)) if __name__ == '__main__': -
theteachr revised this gist
Sep 4, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -61,7 +61,7 @@ def main(): print(inc.inc.square.inc << 2) # 11 print((inc.inc.square.inc * 2) << 2) # 146 print((inc * 4) << 2) # 6 print(Arg(2) >> inc) # 3 print(Arg([1, 2]) >> (curried_map << square)) -
theteachr revised this gist
Sep 4, 2022 . No changes.There are no files selected for viewing
-
theteachr revised this gist
Sep 4, 2022 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,9 +12,6 @@ def __init__(self, f): def __lshift__(self, rhs): return self.f(rhs) def __getattr__(self, f): @BitShiftFunc def composed(x): @@ -69,4 +66,4 @@ def main(): if __name__ == '__main__': main() -
theteachr revised this gist
Sep 4, 2022 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,20 @@ class Arg: def __init__(self, val) -> None: self.val = val def __rshift__(self, f): return f(self.val) class BitShiftFunc: def __init__(self, f): self.f = f def __lshift__(self, rhs): return self.f(rhs) def __rshift__(self, rhs): return self.f(rhs) def __getattr__(self, f): @BitShiftFunc def composed(x): @@ -39,6 +49,11 @@ def cube(x): return x ** 3 @BitShiftFunc def curried_map(f): return lambda lst: list(map(f, lst)) def main(): print(BitShiftFunc(cube) << 3) # 27 print(BitShiftFunc(len) << 'Hello') # 5 @@ -49,6 +64,8 @@ def main(): print(inc.inc.square.inc << 2) # 11 print((inc.inc.square.inc * 2) << 2) # 146 print((inc * 4) << 2) # 6 print(Arg(2) >> inc) # 6 print(Arg([1, 2]) >> (curried_map << square)) if __name__ == '__main__': -
theteachr created this gist
Sep 4, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ class BitShiftFunc: def __init__(self, f): self.f = f def __lshift__(self, rhs): return self.f(rhs) def __getattr__(self, f): @BitShiftFunc def composed(x): return self.f(globals()[f](x)) return composed def __mul__(self, times): @BitShiftFunc def runner(x): start = x for _ in range(times): start = self.f(start) return start return runner def __call__(self, *args, **kwds): return self.f(*args, **kwds) @BitShiftFunc def square(x): return x * x @BitShiftFunc def inc(x): return x + 1 def cube(x): return x ** 3 def main(): print(BitShiftFunc(cube) << 3) # 27 print(BitShiftFunc(len) << 'Hello') # 5 print(square(2)) # 4 print(square << 2) # 4 print(square.inc << 2) # 9 print(inc.square << 2) # 5 print(inc.inc.square.inc << 2) # 11 print((inc.inc.square.inc * 2) << 2) # 146 print((inc * 4) << 2) # 6 if __name__ == '__main__': main()