Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Function-composition/Python/function-composition-5.py
Normal file
23
Task/Function-composition/Python/function-composition-5.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Contents of `pip install compositions'
|
||||
|
||||
class Compose(object):
|
||||
def __init__(self, func):
|
||||
self.func = func
|
||||
|
||||
def __call__(self, x):
|
||||
return self.func(x)
|
||||
|
||||
def __mul__(self, neighbour):
|
||||
return Compose(lambda x: self.func(neighbour.func(x)))
|
||||
|
||||
# from composition.composition import Compose
|
||||
if __name__ == "__main__":
|
||||
# Syntax 1
|
||||
@Compose
|
||||
def f(x):
|
||||
return x
|
||||
|
||||
# Syntax 2
|
||||
g = Compose(lambda x: x)
|
||||
|
||||
print((f * g)(2))
|
||||
Loading…
Add table
Add a link
Reference in a new issue