Last active
November 14, 2019 20:46
-
-
Save julienroubieu/fbb7e1467ab44203a09f to your computer and use it in GitHub Desktop.
Revisions
-
julienroubieu revised this gist
May 13, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ import java.util.Optional /** * Conversions between Scala Option and Java 8 Optional. */ object JavaOptionals { implicit def toRichOption[T](opt: Option[T]): RichOption[T] = new RichOption[T](opt) -
julienroubieu revised this gist
May 13, 2015 . 1 changed file with 7 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,24 +4,22 @@ import java.util.Optional * Implicit conversions between Scala Option and Java 8 Optional. */ object JavaOptionals { implicit def toRichOption[T](opt: Option[T]): RichOption[T] = new RichOption[T](opt) implicit def toRichOptional[T](optional: Optional[T]): RichOptional[T] = new RichOptional[T](optional) } class RichOption[T] (opt: Option[T]) { /** * Transform this Option to an equivalent Java Optional */ def toOptional: Optional[T] = Optional.ofNullable(opt.getOrElse(null).asInstanceOf[T]) } class RichOptional[T] (opt: Optional[T]) { /** * Transform this Optional to an equivalent Scala Option */ def toOption: Option[T] = if (opt.isPresent) Some(opt.get()) else None } -
julienroubieu renamed this gist
May 13, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
julienroubieu created this gist
May 13, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ import java.util.Optional /** * Implicit conversions between Scala Option and Java 8 Optional. */ object JavaOptionals { /** * Transform a Scala Option[T] to a Java Optional[T] */ implicit def toRichOption[T](opt: Option[T]): RichOption[T] = new RichOption[T](opt) /** * Transform a Java Optional[T] to a Scala Option[T] */ implicit def toRichOptional[T](optional: Optional[T]): RichOptional[T] = new RichOptional[T](optional) } class RichOption[T] (opt: Option[T]) { def toOptional: Optional[T] = Optional.ofNullable(opt.getOrElse(null).asInstanceOf[T]) } class RichOptional[T] (opt: Optional[T]) { def toOption: Option[T] = if (opt.isPresent) Some(opt.get()) else None }