Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list0() improvements #55

Closed
jmbarbone opened this issue Feb 15, 2024 · 0 comments · Fixed by #58
Closed

list0() improvements #55

jmbarbone opened this issue Feb 15, 2024 · 0 comments · Fixed by #58
Labels
enhancement New feature or request
Milestone

Comments

@jmbarbone
Copy link
Owner

library(fuj)

lst <- function(...) {
  e <- as.list(substitute(list(...)))[-1L]
  lapply(e[!vapply(e, identical, NA, substitute(), USE.NAMES = FALSE)], eval)
}

# list0() doesn't do well with a few edge bases
try(list0())
#> Warning in seq_len(i - off): first element used of 'length.out' argument
#> Error in seq_len(i - off) : 
#>   argument must be coercible to non-negative integer
try(list0(b = , ))
#> Error in names(out) <- names(mc)[-1L][seq_len(i - off)] : 
#>   'names' attribute [1] must be the same length as the vector [0]
try(list0(a = 1, , ))
#> Error in names(out) <- names(mc)[-1L][seq_len(i - off)] : 
#>   'names' attribute [2] must be the same length as the vector [1]

# newer implementation doesn't have these issues
lst()
#> list()
lst(b = , )
#> named list()
lst(a = 1, , )
#> $a
#> [1] 1

# and it's faster
foo <- "hello"
bench::mark(
  list0 = list0(a = 1, b = 2, , 3, foo, list),
  lst = lst(a = 1, b = 2, , 3, foo, list, b = , )
)
#> # A tibble: 2 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 list0         270µs    299µs     2439.        0B     2.07
#> 2 lst           124µs    130µs     6912.        0B     4.12

Created on 2024-02-15 with reprex v2.1.0

@jmbarbone jmbarbone added the enhancement New feature or request label Feb 15, 2024
@jmbarbone jmbarbone added this to the fuj 0.2.0 milestone Feb 15, 2024
jmbarbone added a commit that referenced this issue Feb 20, 2024
jmbarbone added a commit that referenced this issue Feb 20, 2024
jmbarbone added a commit that referenced this issue Feb 20, 2024
@jmbarbone jmbarbone mentioned this issue Feb 20, 2024
jmbarbone added a commit that referenced this issue Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant