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

mapmatches #36

Open
ym-han opened this issue Dec 18, 2020 · 10 comments
Open

mapmatches #36

ym-han opened this issue Dec 18, 2020 · 10 comments

Comments

@ym-han
Copy link

ym-han commented Dec 18, 2020

The docs at http://shashi.biz/FileTrees.jl/patterns/ mention the function mapmatches, but that doesn't actually seem to be available. But I could be missing something really simple.

@DrChainsaw
Copy link
Collaborator

Can't find it either.

@sashi, should it be in there? From the description it seems a bit similar to mapsubtrees but I can't tell for sure if it should do the same thing.

@sashi
Copy link

sashi commented Feb 13, 2021

@DrChainsaw wrong sashi, was it supposed to be for @shashi ?

@DrChainsaw
Copy link
Collaborator

Uups, forgot that there are more than three people using this platform :)

@singularitti
Copy link

Any updates?

@DrChainsaw
Copy link
Collaborator

Did mapsubtrees(f, t, p) or mapvalues(f, t[p]) work for you?

Unfortunately I don't have access to the docsite so I won't be able to push updates to it. This should maybe be fixed in the long run. It has been less of an issue than it might seem since the package has a pretty stable API.

@shashi
Copy link
Owner

shashi commented Feb 5, 2023

How do I give you access to the docsite? I thought it's just a branch here?

@singularitti
Copy link

singularitti commented Feb 5, 2023

Did mapsubtrees(f, t, p) or mapvalues(f, t[p]) work for you?

I am sorry, but as far as I understand, mapsubtrees returns FileTrees, right? What I need is "applying f to every match". And mapmatches seems to accept more types. I currently cannot run mapsubtrees since the example in the doc is not a valid Julia example:

t = maketree("dir"=>([string(j)=>[(name=string(i), value=(i,j)]
                        for i=1:2] for j=1:3]

t1 = mapsubtrees("*") do subtree
    reducevalues(vcat, subtree)
end

@DrChainsaw
Copy link
Collaborator

@shashi : Not sure either what is needed. Whenever I push the doc job fails. Unfortunately the logs have expired but I'm pretty certain it is some kind of "unauthenticated" failure. Perhaps it is just some secret that needs to be configured.

Currently the docs seem to be hosted in some domain which has your name in it (http://shashi.biz/). Perhaps things will just work if I point to the github pages. Let me know if this is ok with you.

@singularitti

I am sorry, but as far as I understand, mapsubtrees returns FileTrees, right?

Yes, all map functions return a FileTree.

What I need is "applying f to every match".

This is exactly what the map-functions do. You need to select the appropriate map function depending on what you want f to have as input:

  • map => f is given nodes (Files or FileTrees or just Files if dirs=false) and is expected to return a File or FileTree.
  • mapvalues => f is given the value attached to a node and is expected to return a new value (which may have any type) for that node
  • mapsubtrees => f is given nodes (Files or FileTrees or just Files if dirs=false) and may return either nodes or just values.

Both map and mapvalues work on the entire tree they are given, so there is no need for them to have a pattern argument. Just apply it to the tree before providing it (e.g. mapvalues(f, mytree[r"somepattern"]))).

the example in the doc is not a valid Julia example

Uuups! This needs to be fixed of course.

Here is a valid example in the meantime:

julia> t = maketree("dir"=>([string(j)=>[(name=string(i), value=(i,j))  for i=1:2] for j=1:3]))
dir/
├─ 1/
│  ├─ 1 (Tuple{Int64, Int64})
│  └─ 2 (Tuple{Int64, Int64})
├─ 2/
│  ├─ 1 (Tuple{Int64, Int64})
│  └─ 2 (Tuple{Int64, Int64})
└─ 3/
   ├─ 1 (Tuple{Int64, Int64})
   └─ 2 (Tuple{Int64, Int64})


julia> mapsubtrees(t, r"[1,3]") do st
       reducevalues(vcat, st)
       end
dir/
├─ 1/ (2-element Vector{Tuple{Int64, Int64}})
├─ 2/
│  ├─ 1 (Tuple{Int64, Int64})
│  └─ 2 (Tuple{Int64, Int64})
└─ 3/ (2-element Vector{Tuple{Int64, Int64}})

@shashi
Copy link
Owner

shashi commented Feb 6, 2023

Currently the docs seem to be hosted in some domain which has your name in it (http://shashi.biz/).

that's just because shashi.github.io is aliased to shashi.biz... It would be possible to serve it on a different domain though.

@shashi
Copy link
Owner

shashi commented Feb 6, 2023

I think the way Franklin works has changed. Need to update the github action.

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

No branches or pull requests

5 participants