-
Notifications
You must be signed in to change notification settings - Fork 6
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
direct filter! api for FileTree
?
#43
Comments
FileTree
?FileTree
?
Yikes, I use regexes all the time when using FileTrees. Is it possible to get an ELI5 version of this issue? When I see |
anti-pattern because |
Ah, now I understand. I guess it is just to enable the convenient bracket syntax, similar to what e.g. DataFrames and Dicts do. Not saying you don't have a point, but FileTrees are not arrays so maybe they don't need to follow array conventions. |
Couldn't agree more with the original statement that this is not the intuitive way. Persoanlly, I would even like to have a filter option at tree creation. I.e., allow something like taxi_dir = FileTree("taxi-data", f::Function = x -> true) # by default no filtering or a keyword |
In fact, I didn't even understand that the way to create a tree of "only .x files" was by making the full tree and then doing |
I have also missed the predicate when creating the tree. Apart from the filtering, one can also return nothing when loading: ft = load(FileTree("taxi-data")) do f
endswith(name(f), ".x") && return nothing
# code to load .x files
end Unless original author has any objections, I'll accept a PR for the I'm also somewhat sympathetic to the julia> df = DataFrame(a = 1:3, aa = 2:4, b = 11:13)
3×3 DataFrame
Row │ a aa b
│ Int64 Int64 Int64
─────┼─────────────────────
1 │ 1 2 11
2 │ 2 3 12
3 │ 3 4 13
julia> df[:, r"a"]
3×2 DataFrame
Row │ a aa
│ Int64 Int64
─────┼──────────────
1 │ 1 2
2 │ 2 3
3 │ 3 4 If the main gripe is the negation, maybe something like Afaik, julia> t = maketree("root" => [(name="a", value=2), (name="b", value=3)])
root/
├─ a (Int64)
└─ b (Int64)
julia> filter(Returns(true), t)
root/
├─ a (Int64)
└─ b (Int64)
julia> filter(contains("root") ∘ path , t; dirs=false)
root/
├─ a (Int64)
└─ b (Int64)
julia> filter(contains("a") ∘ path , t; dirs=false)
root/
└─ a (Int64)
julia> filter(!contains("a") ∘ path , t; dirs=false)
root/
└─ b (Int64) Something seems off with the docstring though. It seems to merge the docstrings for help?> filter
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
map(f, tree::FileTree; walk=FileTrees.postwalk, dirs=true)
apply f to every node in the tree. To only visit File nodes, pass dirs=false.
walk can be either FileTrees.postwalk or FileTrees.postwalk.
filter(f, tree::FileTree; walk=FileTrees.postwalk, dirs=true)
remove every node x from tree where f(x) is true. f(x) must return a boolean value.
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── |
We should probably have I do not consider the API to be "finished". Would love to accept any PRs with improvements! I tend to avoid having too many options if the same effect can be achieved through existing features. |
This is a great idea! I suppose the equivalent for regex won't make sense though, so maybe we also want the function version? |
IMHO it's an anti-pattern to do:
and currently, you will need to do something close to:
we should probably allow
filter!(pred, tree)
to work directly?(if not not to directly apply predicate on
tree.children
is a debatable question)The text was updated successfully, but these errors were encountered: