Skip to content

Instantly share code, notes, and snippets.

@oisdk
Last active December 31, 2015 16:03
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 oisdk/2c7ac33bf2188528842a to your computer and use it in GitHub Desktop.
Save oisdk/2c7ac33bf2188528842a to your computer and use it in GitHub Desktop.
struct Interact: GeneratorType, SequenceType {
private let prompt: String
init(_ p: String) { prompt = p }
func next() -> String? { print(prompt); return readLine() }
}
for input in Interact("Say something: ") {
print("You said", input)
if input == "q" {
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment