Skip to content

Instantly share code, notes, and snippets.

View joel113's full-sized avatar

Johannes Ehm joel113

View GitHub Profile
package Hokuspokus
object ImplicitMagic extends App {
// implicit lambda which takes an int and returns a string
implicit val i: Int = {
implicit val i = null
implicitly[Int]
package Hokuspokus
object ImplicitMagic extends App {
// implicit lambda which takes an int and returns a string
implicit val f: Int => String = {
// redfines the value f and sets the value implicitly to null
implicit val f = null;
// defines the type class Showable as parametrically polymorphic type where T is the type variable
trait Showable[T] {
def show(t: T): String
}
// implementations of the type class
object Showable {
// implicitly returns a showable applied to the type Int which prints the int as string
implicit def IntShow: Showable[Int] = new Showable[Int] {
package Hokuspokus
object ImplicitMagic extends App {
case class A(a: String, b: String, c: String)
case class B(d: String, e: String, f: String, x: String)
implicit def AtoB: A => B = a => B(a.a, a.b, a.c, a.x)
def print(b: B): Unit = {
package Hokuspokus
object ImplicitMagic extends App {
case class A(a: String, b: String, c: String)
case class B(d: String, e: String, f: String, x: String)
implicit def AtoB: A => B = a => B(a.a, a.b, a.c, a.foobar)
def print(b: B): Unit = {