Created
December 15, 2015 23:05
-
-
Save keybuk/65b39ce12f751e5a1582 to your computer and use it in GitHub Desktop.
Experimenting with Swift protocols
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
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