FileTrees.jl icon indicating copy to clipboard operation
FileTrees.jl copied to clipboard

mapmatches

Open ym-han opened this issue 5 years ago • 10 comments

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.

ym-han avatar Dec 18 '20 07:12 ym-han

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.

DrChainsaw avatar Feb 13 '21 21:02 DrChainsaw

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

sashi avatar Feb 13 '21 21:02 sashi

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

DrChainsaw avatar Feb 13 '21 21:02 DrChainsaw

Any updates?

singularitti avatar Feb 05 '23 00:02 singularitti

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.

DrChainsaw avatar Feb 05 '23 12:02 DrChainsaw

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

shashi avatar Feb 05 '23 22:02 shashi

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

singularitti avatar Feb 05 '23 23:02 singularitti

@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}})

DrChainsaw avatar Feb 06 '23 08:02 DrChainsaw

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 avatar Feb 06 '23 15:02 shashi

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

shashi avatar Feb 06 '23 15:02 shashi