Skip to content

Instantly share code, notes, and snippets.

@markhibberd
Forked from tonymorris/Wibble.scala
Last active December 10, 2015 13:29
Show Gist options
  • Save markhibberd/4441372 to your computer and use it in GitHub Desktop.
Save markhibberd/4441372 to your computer and use it in GitHub Desktop.
object T {
implicit def XIntToInt(x: XInt): Int = x.n
// isomorphism to Int
case class XInt(n: Int)
case class Wibble[A](a: A) {
def wibble(implicit ev: A <:< Int) = a + 9
def map[B](f: A => B) =
Wibble(f(a))
}
object Wobble {
def wobble[A](w: Wibble[A])(implicit ev: A => Int) =
w.map(x => ev(x)).wibble
implicit def wibblable[A](w: Wibble[A])(implicit ev: A => Int): Wibble[Int] =
w.map(x => ev(x))
val w1 = Wibble(3)
// fine
w1.wibble
val w2 = Wibble(XInt(3))
// one of:
wobble(w2)
(w2: Wibble[Int]).wibble
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment