comparison src/StaticDicts/StaticDicts.jl @ 725:e5b51c82f83b feature/static_dict

Docstring for pair type functions
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 17 Mar 2021 20:16:20 +0100
parents a789e789e30f
children 103f61d09a8b
comparison
equal deleted inserted replaced
724:a789e789e30f 725:e5b51c82f83b
42 end 42 end
43 43
44 return default 44 return default
45 end 45 end
46 46
47 firsttype(::Pair{T1,T2}) where {T1,T2} = T1
48 secondtype(::Pair{T1,T2}) where {T1,T2} = T2
49
50 Base.iterate(d::StaticDict) = iterate(d.pairs) 47 Base.iterate(d::StaticDict) = iterate(d.pairs)
51 Base.iterate(d::StaticDict, state) = iterate(d.pairs,state) 48 Base.iterate(d::StaticDict, state) = iterate(d.pairs,state)
52 49
53 Base.length(d::StaticDict) = length(d.pairs) 50 Base.length(d::StaticDict) = length(d.pairs)
54 51
56 # TODO documentation: duplicate keys not allowed atm. will error 53 # TODO documentation: duplicate keys not allowed atm. will error
57 function Base.merge(d1::StaticDict, d2::StaticDict) 54 function Base.merge(d1::StaticDict, d2::StaticDict)
58 return StaticDict(d1.pairs..., d2.pairs...) 55 return StaticDict(d1.pairs..., d2.pairs...)
59 end 56 end
60 57
58
59 """
60 firsttype(::Pair{T1,T2})
61
62 The type of the first element in the pair.
63 """
64 firsttype(::Pair{T1,T2}) where {T1,T2} = T1
65
66 """
67 secondtype(::Pair{T1,T2})
68
69 The type of the secondtype element in the pair.
70 """
71 secondtype(::Pair{T1,T2}) where {T1,T2} = T2
72
61 end # module 73 end # module