Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ChrisMarshallNY
Created April 27, 2020 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisMarshallNY/351a206b71c894e108f8c00393702d56 to your computer and use it in GitHub Desktop.
Save ChrisMarshallNY/351a206b71c894e108f8c00393702d56 to your computer and use it in GitHub Desktop.
struct A<T: Hashable>: Hashable {
static func == (lhs: A<T>, rhs: A<T>) -> Bool { lhs.tVar == rhs.tVar }
let tVar: T
init(_ inVat: T) {
tVar = inVat
}
}
let arVal = [A<Int>](arrayLiteral: A(0), A(1), A(2))
arVal.forEach { print($0.tVar) }
let arDict: [A<Int>: Int] = [
arVal[0]: arVal[0].tVar,
arVal[1]: arVal[1].tVar,
arVal[2]: arVal[2].tVar
]
arDict.forEach { print("\($0.key): \($0.value)") }
// Prints:
// 0
// 1
// 2
// A<Int>(tVar: 2): 2
// A<Int>(tVar: 0): 0
// A<Int>(tVar: 1): 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment