Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Function-composition/Python/function-composition-3.py
Normal file
36
Task/Function-composition/Python/function-composition-3.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from math import (acos, cos, asin, sin)
|
||||
|
||||
|
||||
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
|
||||
def compose(g, f):
|
||||
'''Right to left function composition.'''
|
||||
return lambda x: g(f(x))
|
||||
|
||||
|
||||
# main :: IO ()
|
||||
def main():
|
||||
'''Test'''
|
||||
|
||||
print(list(map(
|
||||
lambda f: f(0.5),
|
||||
zipWith(compose)(
|
||||
[sin, cos, lambda x: x ** 3.0]
|
||||
)([asin, acos, lambda x: x ** (1 / 3.0)])
|
||||
)))
|
||||
|
||||
|
||||
# GENERIC FUNCTIONS ---------------------------------------
|
||||
|
||||
|
||||
# zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
|
||||
def zipWith(f):
|
||||
'''A list constructed by zipping with a
|
||||
custom function, rather than with the
|
||||
default tuple constructor.'''
|
||||
return lambda xs: lambda ys: (
|
||||
map(f, xs, ys)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue