comparison src/StaticDicts/StaticDicts.jl @ 739:e716602f1d62 feature/static_dict

Fix documentation and remove TBD
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 17 Mar 2021 21:56:55 +0100
parents ca4f17efb279
children 94941a062124
comparison
equal deleted inserted replaced
738:0ed147a4068a 739:e716602f1d62
1 module StaticDicts 1 module StaticDicts
2 2
3 export StaticDict 3 export StaticDict
4 4
5 """ 5 """
6 StaticDict{K,V,N}(NTuple{N,Pair{K,V}}) <: AbstractDict 6 StaticDict{K,V,N} <: AbstractDict{K,V}
7 7
8 A static dictionary implementing the interface for an `AbstractDict`. A 8 A static dictionary implementing the interface for an `AbstractDict`. A
9 `StaticDict` is fully immutable and after creation no changes can be made. 9 `StaticDict` is fully immutable and after creation no changes can be made.
10 10
11 The immutable nature means that `StaticDict`s can be compared with `===`, in 11 The immutable nature means that `StaticDict` can be compared with `===`, in
12 constrast to regular `Dict`s or `ImmutableDict`s which can not. (See 12 constrast to regular `Dict` or `ImmutableDict` which can not. (See
13 https://github.com/JuliaLang/julia/issues/4648 for details) One important 13 https://github.com/JuliaLang/julia/issues/4648 for details) One important
14 aspect of this is that `StaticDict` can be used in a struct while still 14 aspect of this is that `StaticDict` can be used in a struct while still
15 allowing the struct to be comared using the default implementation of `==` for 15 allowing the struct to be comared using the default implementation of `==` for
16 structs. 16 structs.
17 17
39 end 39 end
40 40
41 StaticDict(pairs::NTuple{N,Pair} where N) = StaticDict(pairs...) 41 StaticDict(pairs::NTuple{N,Pair} where N) = StaticDict(pairs...)
42 42
43 function Base.get(d::StaticDict, key, default) 43 function Base.get(d::StaticDict, key, default)
44 for p ∈ d.pairs # TBD: Is this the best? Should we use the iterator on `d`? 44 for p ∈ d.pairs
45 if key == p.first 45 if key == p.first
46 return p.second 46 return p.second
47 end 47 end
48 end 48 end
49 49