All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.kinoplan.utils.implicits.AnySyntax.scala Maven / Gradle / Ivy

There is a newer version: 0.0.41
Show newest version
package io.kinoplan.utils.implicits

import scala.util.Try

final private[implicits] class AnyOps(private val value: Any) extends AnyVal {

  @inline
  def toIntOption: Option[Int] = value match {
    case i: Int    => Some(i)
    case d: Double => Some(d.toInt)
    case f: Float  => Some(f.toInt)
    case l: Long   => Some(l.toInt)
    case s: String => Try(s.toInt).toOption
    case _         => None
  }

}

trait AnySyntax {
  implicit final def syntaxAnyOps(value: Any): AnyOps = new AnyOps(value)
}

object AnySyntax extends AnySyntax




© 2015 - 2024 Weber Informatics LLC | Privacy Policy