Skip to content

Instantly share code, notes, and snippets.

@igoticecream
Last active January 31, 2017 18:35
Show Gist options
  • Save igoticecream/45b466e2b2069279833316451d36fa66 to your computer and use it in GitHub Desktop.
Save igoticecream/45b466e2b2069279833316451d36fa66 to your computer and use it in GitHub Desktop.
Example of implicit classes on Scala
package com.igoticecream.wrike.util
object Utils {
implicit class IntWithTimes(x: Int) {
def times[A](f: => A): Unit = {
def loop(current: Int): Unit = {
if (current > 0) {
f
loop(current - 1)
}
}
loop(x)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment