Skip to content

Instantly share code, notes, and snippets.

@Jacoby6000
Last active August 29, 2015 14:16
Show Gist options
  • Save Jacoby6000/3b24d8397491c0f92cb4 to your computer and use it in GitHub Desktop.
Save Jacoby6000/3b24d8397491c0f92cb4 to your computer and use it in GitHub Desktop.
Scala extension methods
object Implicits {
implicit class PimpedString(str: String) {
def everyNthChar(skipNum: Int) = (for (i <- 0 until str.length if i%skipNum==0) yield str(i)).mkString
//Other methods I want strings to have go here
}
implicit class PimpedInt(int: Int){
//Other methods I want ints to have do here
}
}
class SomeClassThatUsesImplicits {
import Implicits._
println("Hey Look, I can use methods from PimpedString!".everyNthChar(3))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment