Skip to content

Instantly share code, notes, and snippets.

@joshcough
Last active August 29, 2015 14: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 joshcough/0beb2338da716ef2a406 to your computer and use it in GitHub Desktop.
Save joshcough/0beb2338da716ef2a406 to your computer and use it in GitHub Desktop.
import scalaz.Contravariant
trait Go[-I,O] { def go(i:I): O }
object Go {
implicit def GoContravariant[O]: Contravariant[Go[?,O]] =
new Contravariant[Go[?, O]] {
def contramap[A, B](r: Go[A, O])(f: B => A): Go[B, O] =
new Go[B, O] { def go(b: B): O = r go f(b) }
}
import scalaz.syntax.contravariant._
val g1 = new Go[String, Int] { def go(a: String) = a.length }
val g2 = g1.contramap { cs: List[Char] => cs.mkString }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment