The package lazyseq
implements a lazy version of base::list
. All
elements are only evaluated when they are needed. E.g. when you convert
the lazy_list
to a normal list
or when you access a single element.
All very experimental.
remotes::install_github("dirkschumacher/lazyseq")
This is a basic example:
library(lazyseq)
content <- 42
ll <- lazy_list(
(function() {print("eval"); 1})(),
(function() !!content)(),
stop("will never be executed")
)
ll
#> <lazy_list[3]>
ll[[1]]
#> [1] "eval"
#> [1] 1
ll[[2]]
#> [1] 42
as.list(ll[-3])
#> [1] "eval"
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 42
Feel free to contribute. Ideally post an issue first or ping me on Twitter, but all contributions are welcome.
Please note that the lazyseq project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.