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

Consider list_merge() #200

Closed
jmbarbone opened this issue May 18, 2023 · 0 comments · Fixed by #201
Closed

Consider list_merge() #200

jmbarbone opened this issue May 18, 2023 · 0 comments · Fixed by #201
Milestone

Comments

@jmbarbone
Copy link
Owner

jmbarbone commented May 18, 2023

https://gist.github.com/jmbarbone/6d5092635866d69d58ac44af67a43869

merge_list <- function(x, y, keep = c("right", "left")) {
  keep <- match.arg(keep)
  x <- x %||% list()
  y <- y %||% list()
  stopifnot(is.list(x), is.list(y))
  x <- Filter(Negate(is.null), as.list(x))
  y <- Filter(Negate(is.null), as.list(y))
  c(x, y)[!duplicated(c(names(x), names(y)), fromLast = keep == "right")]
}


merge_list(
  list(a = 1, b = 2, c = NULL),
  list(a = 2, c = 3)
)
#> $b
#> [1] 2
#> 
#> $a
#> [1] 2
#> 
#> $c
#> [1] 3

merge_list(
  list(a = 1, b = 2, c = NULL),
  list(a = 2, c = 3),
  keep = "left"
)
#> $a
#> [1] 1
#> 
#> $b
#> [1] 2
#> 
#> $c
#> [1] 3
@jmbarbone jmbarbone added this to the future milestone May 18, 2023
@jmbarbone jmbarbone transferred this issue from jmbarbone/fuj Aug 6, 2023
jmbarbone added a commit that referenced this issue Aug 6, 2023
jmbarbone added a commit that referenced this issue Aug 6, 2023
jmbarbone added a commit that referenced this issue Aug 6, 2023
@jmbarbone jmbarbone mentioned this issue Aug 11, 2023
jmbarbone added a commit that referenced this issue Oct 16, 2023
jmbarbone added a commit that referenced this issue Oct 16, 2023
@jmbarbone jmbarbone modified the milestones: future, 0.7.0 Oct 19, 2023
jmbarbone added a commit that referenced this issue Oct 20, 2023
jmbarbone added a commit that referenced this issue Oct 20, 2023
jmbarbone added a commit that referenced this issue Oct 20, 2023
jmbarbone added a commit that referenced this issue Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant