Skip to content

Instantly share code, notes, and snippets.

@dgouyette
Created December 11, 2017 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgouyette/62a64e6dfc5cd817750f48a6e9d1118d to your computer and use it in GitHub Desktop.
Save dgouyette/62a64e6dfc5cd817750f48a6e9d1118d to your computer and use it in GitHub Desktop.
val t1Int : Option[Int] = Some(5)
val t2Int :Option[Int]= Some(6)
val t1String : Option[String] = Some("5")
val t2String :Option[String]= Some("6")
case class MyTuple2[T](a : Option[T], b : Option[T]){
def mapN(f : (T, T)=> T) :Option[T] = {
(a, b) match {
case (Some(a1), Some(b1))=>Some(f(a1, b1))
case _=> None
}
}
}
object MyTuple2 {
implicit def t2x[T](t : (Option[T], Option[T]) ) = MyTuple2(t._1, t._2)
}
import MyTuple2._
(t1Int, None).mapN(_ + _)
(t1Int, t2Int).mapN(_ + _)
(t1String, t2String).mapN(_ + _)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment