Skip to content

Instantly share code, notes, and snippets.

@aaronlelevier
Created October 23, 2019 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronlelevier/3aaa589cd6e7f4e28a3c3c5bccf5033a to your computer and use it in GitHub Desktop.
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
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