Skip to content

Instantly share code, notes, and snippets.

@Summertime
Last active August 12, 2024 09:02
Show Gist options
  • Save Summertime/b239eefcaafaf0f3d4c2f0aa2cbb23cb to your computer and use it in GitHub Desktop.
Save Summertime/b239eefcaafaf0f3d4c2f0aa2cbb23cb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from functools import wraps
class Interpolation:
def __init__(self, getvalue):
self.getvalue = getvalue
def eager_tag(func):
@wraps(func)
def wrapper(*args):
newargs = []
for arg in args:
match arg:
case Interpolation() as ip:
# Avoiding binding issues
newargs.append(
Interpolation( (lambda v: lambda: v)(ip.getvalue()) )
)
case other:
newargs.append(other)
return func(*newargs)
return wrapper
@eager_tag
def lazy(*args):
def _lazy():
for arg in args:
match arg:
case Interpolation() as ip:
print(ip.getvalue())
case other:
print(other)
return _lazy
a,b = 1,2
l = lazy(
'a', Interpolation(lambda: a),
'b', Interpolation(lambda: b),
)
a,b = 3,4
l()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment