Skip to content

Instantly share code, notes, and snippets.

@xlc
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xlc/c5fc00684416c919007e to your computer and use it in GitHub Desktop.
Save xlc/c5fc00684416c919007e to your computer and use it in GitHub Desktop.
struct Point3D {
var x: Int
var y: Int
var z: Int
}
protocol Point3DGenerator {
mutating func next() -> Point3D
}
struct Point3DGeneratorImpl {
var current: Point3D
init(_ cur: Point3D) {
current = cur
}
mutating func next() -> Point3D {
current.x += 2
current.y -= 2
current.z *= 2
return current
}
}
func generateThree(generator: Point3DGenerator) -> (Point3D, Point3D, Point3D) {
return (generator.next(), generator.next(), generator.next())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment