Created
June 4, 2014 13:47
-
-
Save ahti/bd96477ebd631fecb98d to your computer and use it in GitHub Desktop.
Swift subscript overloading and vargs
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
class Foo { | |
subscript(idxs: Int...) -> Int { | |
get { | |
return idxs.reduce(1, combine: *) | |
} | |
} | |
subscript(idxs: Array<Int>) -> Int { | |
get { | |
return idxs.reduce(1, combine: *) | |
} | |
} | |
} | |
let a = Foo(), list = [1, 2, 5] | |
a[list] // => 10 | |
a[1,2,3] // => 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment