Created
May 19, 2015 20:12
-
-
Save lildata/8b2a437251812a8c86e9 to your computer and use it in GitHub Desktop.
how to create a X times syntax with implicits, also cool for DSLs
This file contains 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
implicit def intWithTimes(n: Int) = new { | |
def times(f: => Unit) = 1 to n foreach {_ => f} | |
} | |
5 times { | |
println("Hello World") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment