Skip to content

Instantly share code, notes, and snippets.

@Ben-G
Created April 13, 2016 05:08
Show Gist options
  • Save Ben-G/039e0fd20fddb0e9924df4db333667bb to your computer and use it in GitHub Desktop.
Save Ben-G/039e0fd20fddb0e9924df4db333667bb to your computer and use it in GitHub Desktop.
Can't dynamically check for fulfillment of type constraints
//: Playground - noun: a place where people can play
import Cocoa
let a: Int? = 3
let b: Int? = 3
public func equateThem <T: Equatable>(lhs : Optional<T>, rhs : Optional<T>) -> Bool {
return lhs! == rhs!
}
func takeTwo<T>(a: Optional<T>, b: Optional<T>) {
// no way to cast in a way to enforce same type requirement & Equatable
// would need something like: (if <T: Equatable> let a = as as? T, let b = as? T)
equateThem(a, rhs: b)
}
takeTwo(a, b: b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment