Skip to content

Instantly share code, notes, and snippets.

@tonymorris

tonymorris/nope.scala Secret

Created Aug 7, 2020
Embed
What would you like to do?
// uncomment variance annotations -> compiler error
trait IdentityCompose[:=>[/* - */_, /* + */_]] {
def identity[A]: A :=> A
def compose[A, B, C](bc: B :=> C, ab: A :=> B): A :=> C
}
case class ToFrom[A, B](to: A => B, fr: B => A)
object ToFrom {
def ToFromIdentityCompose: IdentityCompose[ToFrom] =
new IdentityCompose[ToFrom] {
def identity[A]: A ToFrom A =
ToFrom(a => a, a => a)
def compose[A, B, C](bc: B ToFrom C, ab: A ToFrom B): A ToFrom C =
ToFrom(bc.to compose ab.to, bc.fr andThen ab.fr)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment