Skip to content

Instantly share code, notes, and snippets.

@ms-tg
Created March 18, 2013 14:38
Show Gist options
  • Save ms-tg/5187602 to your computer and use it in GitHub Desktop.
Save ms-tg/5187602 to your computer and use it in GitHub Desktop.
Example of Scala enrich-my-library pattern: adding String#toIntOpt
package enriching_example
import scala.util.control.Exception.allCatch
case class StringWithToInt(s: String) {
def toIntOpt: Option[Int] = allCatch opt { s.toInt }
}
implicit def string2stringWithToInt(s: String) = StringWithToInt(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment