Created
April 13, 2016 05:08
-
-
Save Ben-G/039e0fd20fddb0e9924df4db333667bb to your computer and use it in GitHub Desktop.
Can't dynamically check for fulfillment of type constraints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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