Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Apr 22, 2021
1 parent 4ed2a9d commit 2c008eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Containers/container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ function _sparseaxisarray(dict::Dict{Any,Any}, f, indices)
return SparseAxisArray(d)
end

# Don't use length-1 tuples if there is only one index!
_container_key(i::Tuple) = i
_container_key(i::Tuple{T}) where {T} = i[1]

function container(f::Function, indices, D::Type{<:AbstractDict})
# Don't use length-1 tuples if there is only one index!
key(i) = length(i) == 1 ? i[1] : i
return D(key(i) => f(i...) for i in indices)
return D(_container_key(i) => f(i...) for i in indices)
end

function container(::Function, ::Any, D::Type)
Expand Down
6 changes: 5 additions & 1 deletion test/Containers/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ using Test
@test z[1, 2] == 3
end
@testset "Invalid container" begin
@test_throws ErrorException Containers.@container(
err = ErrorException(
"Unable to build a container with the provided type $(Int). " *
"Implement `Containers.container`.",
)
@test_throws err Containers.@container(
x[i = 1:2, j = 1:2],
i + j,
container = Int
Expand Down

0 comments on commit 2c008eb

Please sign in to comment.