/src/main/scala/scalagym/Demo.scala
Scala | 23 lines | 13 code | 7 blank | 3 comment | 1 complexity | 5bccba9f37bf1fd56265e4bf7db61aad MD5 | raw file
1package scalagym 2 3import annotation.tailrec 4 5/** 6 * @author Mario Fusco 7 */ 8object Demo extends Application { 9 10 implicit def intToLooper(n: Int) = new { def times(f: => Unit): Unit = Demo.times(n)(f) } 11 12 twice { 13 3 times { 14 println("Hello world!") 15 } 16 } 17 18 def twice(f: => Unit): Unit = { f; f; } 19 20 @tailrec 21 def times(n: Int)(f: => Unit): Unit = if (n > 0) { f; times(n-1)(f) } 22 23}