Because tuples are not hashable in Swift, I have created a generic struct Couple to contain two elements which combined can be used as a key to a dictionary.
struct Couple<U: Hashable, V: Hashable>: Hashable {
let u: U
let v: V
init( _ u: U, _ v: V ) {
self.u = u
self.v = v
}
}
var dictionary: [ Couple<Int,Int> : Any ] = ...
Now, I would like to extend Dictionary using Couple generically.
extension Dictionary where Key == Couple<U: Hashable, V: Hashable>, Value == Any {
func exampleConvertToArray() -> [ ( U, V, Any ) ] {
}
}
The compiler complains no matter how I refer to Couple, U, V on the extension statement. If I instead add the generic to the function definition, the compiler also complains.
If the types are not generic (extension Dictionary where Key == Couple<Int, Int>, Value == Any), all is fine.
How can I create this generic extension?