Mercurial > repos > public > sbplib_julia
diff src/StaticDicts/StaticDicts.jl @ 736:b5d9fbcdcef1 feature/static_dict
Add a constuctor taking a tuple
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 17 Mar 2021 21:45:59 +0100 |
parents | 3e0b0b44868e |
children | ca4f17efb279 |
line wrap: on
line diff
--- a/src/StaticDicts/StaticDicts.jl Wed Mar 17 21:29:37 2021 +0100 +++ b/src/StaticDicts/StaticDicts.jl Wed Mar 17 21:45:59 2021 +0100 @@ -23,12 +23,10 @@ struct StaticDict{K,V,N} <: AbstractDict{K,V} pairs::NTuple{N,Pair{K,V}} - # TBD: Why doesn't `pairs::NTuple{N,Pair{K,V}}` work? function StaticDict{K,V,N}(pairs::Tuple) where {K,V,N} if !allunique(first.(pairs)) throw(ArgumentError("keys must be unique (for now)")) end - return new{K,V,N}(pairs) end end @@ -40,6 +38,8 @@ return StaticDict{K,V,N}(pairs) end +StaticDict(pairs::NTuple{N,Pair} where N) = StaticDict(pairs...) + function Base.get(d::StaticDict, key, default) for p ∈ d.pairs # TBD: Is this the best? Should we use the iterator on `d`? if key == p.first