Created
November 12, 2020 19:15
-
-
Save baileywickham/3dc71f1769b98db6d90c914d7d47a1bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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