How to pass lazy variables to a functions parameters without them being evaluated unless returned
language-agnostic, lazy-evaluation, python
Solution
You can use a special object to defer computation until the object is first used. It looks a Lazy Proxy will do what you want.
Problem
This question is aimed at python, although I don't mind users sharing experience from other languages. Basically my problem is trying to pass lazy variables to a function. (in my case i may have no control over the function, so can't change it to take a generator as input). Example (note that dict.get is an example of a function, but it could well be foo) ``` def calc(): sleep(10**100) return 42 def my_args(): yield 'meaning' yield calc() #Instead of meaning_of_life = dict_.get('meaning', calc()) #I would rather meaning_of_life = dict_.get(my_args) ``` I don't suppose there are any one line elegant solutions? Possibly complicated monkey patching is required? (if so it's not worth it for me to try). Thanks.