Skip to content

Instantly share code, notes, and snippets.

@kergoth
Created April 18, 2023 16:40
Show Gist options
  • Save kergoth/2dafec9aae5efd47959cfe655bb0b82b to your computer and use it in GitHub Desktop.
Save kergoth/2dafec9aae5efd47959cfe655bb0b82b to your computer and use it in GitHub Desktop.
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