diff src/StaticDicts/StaticDicts.jl @ 720:172c55c4cf2e feature/static_dict

Dissalow duplicate keys
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 16 Mar 2021 22:35:40 +0100
parents 2f8c67c5979e
children a789e789e30f
line wrap: on
line diff
--- a/src/StaticDicts/StaticDicts.jl	Tue Mar 16 17:28:40 2021 +0100
+++ b/src/StaticDicts/StaticDicts.jl	Tue Mar 16 22:35:40 2021 +0100
@@ -16,6 +16,15 @@
 """
 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
 
 function StaticDict(pairs::Vararg{Pair})