-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
Joseph Groff mentioned a potential type testing feature:
Ultimately, though, I'd like to see us expose that kind of more expressive efficient type testing in the language too. It would be great if you could do things like [...] without the overhead of the extraneous checks, the need for a value of a type to ask for properties of the type itself, or the implied wrapping of casting something as? P.
func foo<T>(x: T, y: T) -> T {
if where T == Int {
return x + y // we can assume x and y are Int here
}
if <U> where T == Array<U> {
return x + y // we can assume x and y are some kind of Array here
}
if where T: Addable {
return x.add(y) // we can assume x and y conform to Addable here
}
return x
}