one-liner to make a Guava Optional from a scala Option (keep in mind that Guava Optionals are not monadic)
Implicit conversion example
name := "ScalaOptionToGuavaOptional" | |
scalaVersion := "2.10.2" | |
libraryDependencies += "com.google.guava" % "guava" % "14.0.1" | |
libraryDependencies += "com.google.code.findbugs" % "jsr305" % "2.0.1" |
import com.google.common.base.Optional | |
def toOptional[T >: Null](x : Option[T]) : Optional[T] = Optional.fromNullable[T](x.orNull[T]) | |
//examples | |
toOptional(None) | |
toOptional(Some("dude")) | |
toOptional(Some(3)) |