Lazy lists

Run Settings
LanguagePython
Language Version
Run Command
class Lazy: __slots__ = ('thunk', 'result') def __init__(self, thunk): self.thunk = thunk def force(self): if self.thunk is not None: self.result = self.thunk() self.thunk = None return self.result def eager(lazy_list): result = [] while True: cell = lazy_list.force() if cell is None: return result result.append(cell[0]) lazy_list = cell[1] lazy_list = Lazy(lambda: (1, Lazy(lambda: (2, Lazy(lambda: (3, Lazy(lambda: None))))))) print(eager(lazy_list)) print(eager(lazy_list)) print(eager(lazy_list))
Editor Settings
Theme
Key bindings
Full width
Lines