Skip to content

Commit b44749f

Browse files
committed
Clean up write_once_read_many.jl
1 parent cbd071c commit b44749f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/write_once_read_many.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ for f in (:enumerate, :length, :lastindex)
1717
end
1818
end
1919

20-
Base.getindex(w::WriteOnceReadMany, i::Union{Int, INDEX_TYPE, Symbol}) = getindex(w._raw_data, i)
20+
Base.getindex(w::WriteOnceReadMany, i::Union{Integer,Symbol}) = getindex(w._raw_data, i)
21+
Base.get(w::WriteOnceReadMany{<:Dict}, a, b) = get(w._raw_data, a, b)
22+
23+
# Only define setindex! for Dicts, and throw an error if the key already exists
24+
function Base.setindex!(w::DynamicQuantities.WriteOnceReadMany{<:Dict}, i, s::Symbol)
25+
haskey(w._raw_data, s) && throw("Unit $s already exists at index $(w[s])")
26+
setindex!(w._raw_data, i, s)
27+
end
2128

2229
Base.iterate(w::WriteOnceReadMany) = iterate(w._raw_data)
2330
Base.iterate(w::WriteOnceReadMany, i::Int) = iterate(w._raw_data, i)
@@ -33,10 +40,3 @@ for f in (:findfirst, :filter)
3340
end
3441
end
3542

36-
Base.setindex!(w::DynamicQuantities.WriteOnceReadMany{Dict{Symbol, INDEX_TYPE}}, i::Int, s::Symbol) = setindex!(w, INDEX_TYPE(i), s)
37-
function Base.setindex!(w::DynamicQuantities.WriteOnceReadMany{Dict{Symbol, T}}, i::T, s::Symbol) where T <: Union{Int, INDEX_TYPE}
38-
haskey(w._raw_data, s) && throw("Unit $s already exists at index $(w[s])")
39-
setindex!(w._raw_data, i, s)
40-
end
41-
42-
Base.get(w::WriteOnceReadMany{Dict{Symbol, INDEX_TYPE}}, a, b) = get(w._raw_data, a, b)

0 commit comments

Comments
 (0)