Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created March 27, 2015 00:50
Show Gist options
  • Save xuwei-k/7115b330b4ee37d961d0 to your computer and use it in GitHub Desktop.
Save xuwei-k/7115b330b4ee37d961d0 to your computer and use it in GitHub Desktop.
trait FlipFlapper[T] {
def doFlipFlap(x: T): T
}
object FlipFlapper {
def fromFunction[A](f: A => A): FlipFlapper[A] =
new FlipFlapper[A] {
def doFlipFlap(x: A) = f(x)
}
implicit val int =
fromFunction[Int](- _)
implicit val string =
fromFunction[String](_.reverse)
implicit def list[A] =
fromFunction[List[A]](_.reverse)
implicit val boolean =
fromFunction[Boolean](! _)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment