Skip to content

Instantly share code, notes, and snippets.

@knightpop
Created August 3, 2017 15:51
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 knightpop/9ad231a6d4b621e7ebad3bc0115b4e5b to your computer and use it in GitHub Desktop.
Save knightpop/9ad231a6d4b621e7ebad3bc0115b4e5b to your computer and use it in GitHub Desktop.
implicit val optionInt: Option[Int] = Some(1)
implicit val optionBoolean: Option[Boolean] = Some(true)
def getImplicitOptionInt(implicit oInt: Option[Int]): Int = oInt.get
def getImplicitOptionBoolean(implicit oBoolean: Option[Boolean]): Boolean = oBoolean.get
getImplicitOptionInt
getImplicitOptionBoolean
def getImplicitlyOptionA[A: Option]: A = implicitly[Option[A]].get
getImplicitlyOptionA[Int]
getImplicitlyOptionA[Boolean]
trait Parent {
def sayHello: String
}
trait Son extends Parent {
override def sayHello: String = "Hello! I'm Son!"
}
trait Daughter extends Parent {
override def sayHello: String = "Hello! I'm Daughter!"
}
def sayHello[A <: Parent](a: A): Unit = println(a.sayHello)
sayHello(new Son {})
sayHello(new Daughter {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment