Created
January 5, 2016 20:30
-
-
Save justAnotherDev/924d283c4aea0da41ad0 to your computer and use it in GitHub Desktop.
Iterate a tuple in Swift
This file contains hidden or 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
func generatorForTuple(tuple: Any) -> AnyGenerator<Any> { | |
return anyGenerator(Mirror(reflecting: tuple).children.lazy.map { $0.value }.generate()) | |
} | |
let someTuple = ("1", 2, ["3"]) | |
for value in generatorForTuple(someTuple) { | |
print(value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment