Skip to content

Instantly share code, notes, and snippets.

@beccadax
Last active August 29, 2015 14:03
Show Gist options
  • Save beccadax/6ae203e687c75273b55e to your computer and use it in GitHub Desktop.
Save beccadax/6ae203e687c75273b55e to your computer and use it in GitHub Desktop.
This function creates an index/element tuple generator that actually uses the right indices, but it fails with a *really* weird error.
func realEnumerate<C: Swift.Collection>(collection: C) -> GeneratorOf<(C.IndexType, C.GeneratorType.Element)> {
var i: C.IndexType = collection.startIndex
return GeneratorOf() {
if i < collection.endIndex {
// 'i' is flagged in comparison with "'C.IndexType' is not convertible to 'CString'". Whuh?
let value = (i, collection[i])
i = i.successor()
return value
}
else {
return nil
}
}
}
@beccadax
Copy link
Author

Answer on that one: IndexType is not Comparable, which is impossible to tell because most of Collection's definition is missing. Yay for betas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment