Skip to content

Instantly share code, notes, and snippets.

@ottomata
Created April 21, 2017 14:58
Show Gist options
  • Select an option

  • Save ottomata/d33787567d28f08edd0f81a196fadba2 to your computer and use it in GitHub Desktop.

Select an option

Save ottomata/d33787567d28f08edd0f81a196fadba2 to your computer and use it in GitHub Desktop.
object CoolStuff {
implicit class StringImplicits(s: String) {
def withCool(s2: String): String = s + " COOL " + s2
}
implicit class SeqStringImplicits(strings: Seq[String]) {
def joinEm(sep: String = " | "): String = {
// error: not found: value withCool
strings.map(withCool).mkString(sep)
// But this will work:
// strings.map(s => StringImplicits(s).withCool).mkString(sep)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment