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
Mapping over trees #236
Comments
On that note I wonder if the following would be good UI: array_tree(x, ~last)
array_tree(x, list(1, 2, ~last)
x %>% at_depth(~last, f) |
Other useful idiom for tree structures: visit each node twice. Once on the way in, the second time on the way back. See https://stlab.adobe.com/group__asl__tutorials__forest.html The mapped function would get a boolean indicating if this is the second time we see the node. |
Would this map over the deepest level or all leaf nodes? The latter (or some other intelligible version of |
@alistaire47 yes I was thinking x %>% map_tree_if(is_atomic, fn) And maybe have |
What if instead of And what if |
I also wonder about an option to recurse <- function(x, depth) {
if (depth > 1) {
if (is.atomic(x)) {
x
} else {
lapply(x, recurse, depth = depth - 1)
}
} else {
lapply(x, .f, ...)
}
} So that if the list is ragged, you can choose to only operate on lists at a certain level, ignoring branches that aren't that deep. |
at_bottom()
would be likeat_depth()
but at bottom. Useful for tree structures.The text was updated successfully, but these errors were encountered: