dirkschumacher / lazyseq

Lazy R list that evaluate elements only when needed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lazyseq

Lifecycle: experimental

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.

Installation

remotes::install_github("dirkschumacher/lazyseq")

Example

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

Contribute

Feel free to contribute. Ideally post an issue first or ping me on Twitter, but all contributions are welcome.

Code of Conduct

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.

About

Lazy R list that evaluate elements only when needed

License:Other


Languages

Language:R 100.0%