Skip to content

Instantly share code, notes, and snippets.

@keybuk
Created December 15, 2015 23:05
Show Gist options
  • Save keybuk/65b39ce12f751e5a1582 to your computer and use it in GitHub Desktop.
Save keybuk/65b39ce12f751e5a1582 to your computer and use it in GitHub Desktop.
Experimenting with Swift protocols
var y = NSOrderedSet(orderedSet: my)
struct CastingGenerator<G: GeneratorType, T>: GeneratorType {
typealias Element = T
var base: G
init(_ base: G) {
self.base = base
}
mutating func next() -> Element? {
return base.next() as! Element?
}
}
struct CastingSequence<S: SequenceType, T>: SequenceType {
typealias Generator = CastingGenerator<S.Generator, T>
var base: S
init(_ base: S) {
self.base = base
}
func generate() -> Generator {
return CastingGenerator<S.Generator, T>(base.generate())
}
}
var yy = CastingSequence<NSOrderedSet, String>(my)
for test in yy {
print(test)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment