Skip to content

Commit

Permalink
foldl
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeits committed Aug 23, 2018
1 parent 90924d6 commit 28624a4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/trees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ Base.size(p::Path) = size(p.entries)
Base.IndexStyle(::Type{Path}) = IndexLinear()
Base.convert(::Type{Path}, x::AbstractVector{<:AbstractString}) = Path(x)

Base.joinpath(p::Path, s...) = foldl(joinpath, s, init=p)
if VERSION < v"0.7-"
Base.joinpath(p::Path, s...) = foldl(joinpath, p, s)
else
Base.joinpath(p::Path, s...) = foldl(joinpath, s, init=p)
end
Base.joinpath(p::Path, s::Symbol) = joinpath(p, String(s))
Base.joinpath(p::Path, s::AbstractString) = _joinpath(p, split(s, '/'))

_joinpath(p::Path, s::AbstractVector{<:AbstractString}) = foldl(_joinpath, s, init=p)
if VERSION < v"0.7-"
_joinpath(p::Path, s::AbstractVector{<:AbstractString}) = foldl(_joinpath, p, s)
else
_joinpath(p::Path, s::AbstractVector{<:AbstractString}) = foldl(_joinpath, s, init=p)
end
_joinpath(p::Path, s::AbstractString) = isempty(s) ? Path(String[]) : Path(vcat(p.entries, s))

Base.show(io::IO, p::Path) = print(io, string('/', join(p.entries, '/')))
Expand Down

0 comments on commit 28624a4

Please sign in to comment.