Skip to content

Instantly share code, notes, and snippets.

@iKalin
Forked from jverkoey/Tuple+Generator.swift
Created October 26, 2015 13:27
Show Gist options
  • Save iKalin/544ad2d46295ad8bc9f6 to your computer and use it in GitHub Desktop.
Save iKalin/544ad2d46295ad8bc9f6 to your computer and use it in GitHub Desktop.
Tuple enumeration
/** The returned generator will enumerate each value of the provided tuple. */
func generatorForTuple(tuple: Any) -> AnyGenerator<Any> {
return anyGenerator(Mirror(reflecting: tuple).children.lazy.map { $0.value }.generate())
}
// Blogged at http://design.featherless.software/enumerating-tuple-values-swift/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment