Skip to content

Instantly share code, notes, and snippets.

@austinzheng
Created May 26, 2016 04:03
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 austinzheng/25002ac5f1633fa5990354de3bcb77a5 to your computer and use it in GitHub Desktop.
Save austinzheng/25002ac5f1633fa5990354de3bcb77a5 to your computer and use it in GitHub Desktop.
func getString(collection: Any<Collection where .Element == String>, index: Int) -> String {
do collection openas T {
// T is available as a type.
// (Is this true?) T's associated types are also available, since T is opened into an explicit type.
var collectionIndex : T.Index = input.startIndex
for _ = 0..<index {
collectionIndex = collectionIndex.next(collection)
}
let returnValue : T.Element /* e.g. String */ = collection[collectionIndex]
return returnValue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment