-
-
Save Aankhen/2344262 to your computer and use it in GitHub Desktop.
Interactive Input
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
import scala.util.continuations._ | |
// might need to be compiled and run separately due to a bug in App | |
object ContinuationsExample extends App { | |
def prompt(display: String): Boolean = { | |
print(display + " (Y/N) ") | |
Console.readLine.trim.headOption match { | |
case Some('Y') | Some('y') => true | |
case Some('N') | Some('n') => false | |
case _ => prompt(display) | |
} | |
} | |
def delay(duration: Long) = | |
shift { | |
k: (Unit => Boolean) => | |
do { | |
println("%nSleeping for %d milliseconds..." format (duration)) | |
Thread.sleep(duration) | |
} while (k()) | |
} | |
println("Before reset") | |
reset { | |
delay(2000) | |
prompt("Repeat?") | |
} | |
println("\nAfter reset") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment