Last active
August 29, 2015 14:25
-
-
Save joshcough/0beb2338da716ef2a406 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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