Skip to content

Instantly share code, notes, and snippets.

@seasmith
Created July 17, 2019 03:10
Show Gist options
  • Save seasmith/63831e1a5d48ed7f27c494c5d767e421 to your computer and use it in GitHub Desktop.
Save seasmith/63831e1a5d48ed7f27c494c5d767e421 to your computer and use it in GitHub Desktop.
Evaluate a list lazily
# Taken from: https://twitter.com/dirk_sch/status/1151080975952228352
"[[.ll" <- function(x, i) {
rlang::eval_tidy(x$call_list[[i]])
}
lazylist <- function(...) {
calls <- rlang::enexprs(...)
structure(list(call_list = calls), class = "ll")
}
a <- lazylist(1, 2, Sys.sleep(10), 10)
a[[2]]
#> [1] 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment