diff --git a/README.md b/README.md index 48c7226..24b15ec 100755 --- a/README.md +++ b/README.md @@ -113,10 +113,17 @@ file = dfname(["dir1", "dir2"], "my_cool_file", (;A = 1), ".jls") @show file = # file = "dir1/dir2/my_cool_file [A=1].jls" ``` +'Simple' tuples are hashed. This is useful for quick unique data based file names. + +```julia +file = dfname("comment", (1,2,3), ".ext") +@show file = # file = "comment [hash=0x83d91fbc7a900a8f].ext" +``` + To avoid such behavior (if you wanna use a vector as part of the name) use an empty string. ```julia -# Empty strings are ignored in the construction of the name but are relevant is the arguments structure. Now the vector is taken as an ordinary argument and `parse_arg(v::Vector{String})` must be implemented +# Empty strings are ignored in the construction of the name but are relevant in the arguments structure. Now the vector is taken as an ordinary argument and `parse_arg(v::Vector{String})` must be implemented file = dfname("", ["dir1", "dir2"], "my_cool_file", (;A = 1), ".jls") # ERROR: LoadError: parse_arg(v::Vector{String}) not implemented. Type `?parse_arg` for help. ``` diff --git a/src/dfname.jl b/src/dfname.jl index 7644c47..aa91a37 100755 --- a/src/dfname.jl +++ b/src/dfname.jl @@ -33,6 +33,14 @@ parse_arg(pt::NamedTuple) = pt parse_arg(pt::Iterators.Pairs) = parse_arg(Dict(pt...)) parse_arg(pt::Dict) = pt parse_arg(v::Any) = error("parse_arg(v::", typeof(v), ") not implemented. Type `?parse_arg` for help.") +# A tupple will be hashed +function parse_arg(pt::Tuple) + h = hash(0) + for el in pt + h = hash(el, h) + end + return (;hash = repr(h)) +end # ------------------------------------------------------------------- # _argstr