title: Using a protocol to define a collection of KeyPaths with different values
body: <p>Suppose you want to keep track of one or more unique identifier(s). In this case, <code>A</code> has two properties that are considered unique to <code>A</code>, while <code>B</code> has only one property that is unique to <code>B</code>.</p>
  <pre><code>protocol HavingUID {
     // Some way to use KeyPath?
  }
  
  struct A : HavingUID {
     var unique1 : String  
     var unique2 : Int
  }
  
  struct B : HavingUID {
     var unique1 : Double
  }
  
  let a1 = A(unique1:&quot;val&quot;, unique2: 1)
  let a2 = A(unique1:&quot;val&quot;, unique2: 2)
  let b1 = B(unique1:0.5)
  let b2 = B(unique1:0.0)
  let b3 = B(unique1:0.2)
  
  let arrA : [HavingUID] = [a1,a2]
  let arrB : [HavingUID] = [b1,b2,b3]
  
  // How to check arrA and arrB for duplicate UID properties?
  </code></pre>
  <p>If there was just one unique key, we could do something like:</p>
  <pre><code>protocol HavingUID {
     typealias UID
     static var uidKey : KeyPath&lt;Self, UID&gt; {get}
  }
  struct A : HavingUID {
     static var uidKey = A.\unique1
     var unique1 : String
  }
  struct B : HavingUID {
     static var uidKey = B.\uniqueB
     var uniqueB : Int
  }
  </code></pre>
  <p>...but that limits me to one key.</p>