Skip to content

Instantly share code, notes, and snippets.

@Krasnyanskiy
Last active April 17, 2016 14:13
Show Gist options
  • Save Krasnyanskiy/fd3ebb5eb200e1c3436dc836c9bcc2ba to your computer and use it in GitHub Desktop.
Save Krasnyanskiy/fd3ebb5eb200e1c3436dc836c9bcc2ba to your computer and use it in GitHub Desktop.
-scala: fixme (!)
var i = 10
class Condition(closure: (=> Unit) => Condition)(cmd: => Unit) {
def until(condition: => Boolean) = {
if (condition) {
cmd
closure(cmd)
}
}
}
def repeat(cmd: => Unit) = new Condition(repeat)(cmd)
repeat {
println(i)
} until {
i = i - 1; i > 0
}
@Krasnyanskiy
Copy link
Author

Fix
class Repeater(command: => Unit) {
  def until(condition: => Boolean)  {
    command
    if (condition) until(condition)
  }
}

def repeat(command: => Unit) = new Repeater(command)

var x = 0

repeat { x += 1; println(x) } until (x < 10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment