Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object SafeString {
- class StrOps(input: String) {
- private def toOption[A](in: => A) = try {
- Some(in)
- } catch {
- case _: Throwable => None
- }
- def toInt: Option[Int] = toOption(input.toInt)
- def toFloat: Option[Float] = toOption(input.toFloat)
- def toDouble: Option[Double] = toOption(input.toDouble)
- def toLong: Option[Long] = toOption(input.toLong)
- }
- implicit class RichString(val left: String) extends AnyVal {
- def opt: StrOps = new StrOps(left)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement