Skip to content

Instantly share code, notes, and snippets.

@mmaz
Last active December 19, 2015 22:49
Show Gist options
  • Save mmaz/6030687 to your computer and use it in GitHub Desktop.
Save mmaz/6030687 to your computer and use it in GitHub Desktop.
scala Option to Guava Optional
import com.google.common.base.Optional
def toOptional[T](x : Option[T]) : Optional[T] = Optional.fromNullable[T](x.orNull[T])
//examples
toOptional(None)
toOptional(Some("dude"))

Option -> Optional

one-liner to make a Guava Optional from a scala Option (keep in mind that Guava Optionals are not monadic)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment