/src/main/scala/scalagym/Demo.scala

http://github.com/mariofusco/scalagym · Scala · 23 lines · 13 code · 7 blank · 3 comment · 1 complexity · 5bccba9f37bf1fd56265e4bf7db61aad MD5 · raw file

  1. package scalagym
  2. import annotation.tailrec
  3. /**
  4. * @author Mario Fusco
  5. */
  6. object Demo extends Application {
  7. implicit def intToLooper(n: Int) = new { def times(f: => Unit): Unit = Demo.times(n)(f) }
  8. twice {
  9. 3 times {
  10. println("Hello world!")
  11. }
  12. }
  13. def twice(f: => Unit): Unit = { f; f; }
  14. @tailrec
  15. def times(n: Int)(f: => Unit): Unit = if (n > 0) { f; times(n-1)(f) }
  16. }