Created
April 18, 2023 16:40
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 memoize(d, varname, func): | |
"""Calculate the result of func once, replacing the value in the metadata. | |
This will run the function once rather than every time it's used, but unlike | |
immediate expansion, this initial expansion occurs the first time it's used. | |
Example Usage: | |
TESTVAR = "${@memoize(d, 'TESTVAR', lambda: myfunction(d) or '')}" | |
TESTVAR[vardepvalue] = "${TESTVAR}" | |
""" | |
value = func() | |
d.setVar(varname, value) | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment