Skip to content

Instantly share code, notes, and snippets.

@baileywickham
Created November 12, 2020 19:15
Show Gist options
  • Save baileywickham/3dc71f1769b98db6d90c914d7d47a1bc to your computer and use it in GitHub Desktop.
Save baileywickham/3dc71f1769b98db6d90c914d7d47a1bc to your computer and use it in GitHub Desktop.
# Fixed Point Map:
# fpmap(function, fixed_point..., list)
def fpmap(*argv):
if len(argv) < 2:
# bad map paramaters
raise TypeError("fpmap must have at least two arguments")
# function to call
f = argv[0]
# List to pass to map
l = argv[-1]
# Fixed points
fps = argv[1:-1]
if len(fps) == 0:
return map(f, l)
return map(lambda a: f(a, *fps), l)
assert list(fpmap(lambda a, b: a + b, 10, [1, 2, 3])) == [11, 12, 13]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment