one-liner to make a Guava Optional from a scala Option (keep in mind that Guava Optionals are not monadic)
Last active
December 19, 2015 22:49
-
-
Save mmaz/6030687 to your computer and use it in GitHub Desktop.
scala Option to Guava Optional
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.base.Optional | |
def toOptional[T](sop : Option[T]) : Optional[T] = Optional.fromNullable[T](sop.orNull[T]) | |
//examples | |
toOptional(None) | |
toOptional(Some("dude")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment