Skip to content

Commit

Permalink
Merge pull request #3 from AlgebraicJulia/empty-dtry
Browse files Browse the repository at this point in the history
Dtry constructor fixup
  • Loading branch information
olynch authored Aug 22, 2024
2 parents bc596c2 + 6ac1283 commit 6094397
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/dtry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,22 +327,28 @@ function Dtry(pairs::Vector)
frompairs(pairs)
end

function Dtry{A}(pairs...) where {A}
frompairs([pairs...], A)
function Dtry{A}(pair::Pair, pairs...) where {A}
frompairs([pair, pairs...], A)
end

function Dtry{A}() where {A}
Empty{A}()
end

# We don't allow Dtry(), because that would have to be typed as Dtry{Any}, which
# would lead to pain and suffering
function Dtry(pair, pairs...)
function Dtry(pair::Pair, pairs...)
frompairs([pair, pairs...])
end

@tests Dtry begin
@test Dtry{Int}() isa Dtry
@test Dtry(Path([:a]) => 2) == Node(:a => Leaf(2))
@test Dtry([:a] => 2) == Node(:a => Leaf(2))
@test Dtry(Symbol[] => 2) == Leaf(2)
@test_throws Exception Dtry([:a] => 2, [:a, :b] => 3)
@test_throws MethodError Dtry()
@test Dtry{Int}() == Empty{Int}()
end

function flatmap(f, ::Type{B}, d::Dtry{A})::Dtry{B} where {A, B}
Expand Down

0 comments on commit 6094397

Please sign in to comment.