Created
October 23, 2019 19:18
-
-
Save aaronlelevier/3aaa589cd6e7f4e28a3c3c5bccf5033a to your computer and use it in GitHub Desktop.
Python Applicative Pattern - apply a container of functions to a container of values
This file contains 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
def add1(x): | |
return x+1 | |
def double(x): | |
return x+x | |
def square(x): | |
return x*x | |
funs = [add1, double, square] | |
values = [1,2,3] | |
def applicative(funs, values): | |
r = [] | |
for f in funs: | |
r.append([x for x in map(f, values)]) | |
return r | |
applicative(funs, values) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment