Last active
January 28, 2019 23:47
-
-
Save lemastero/5bbc9ab83ffd82bda71aa86b4b7995c9 to your computer and use it in GitHub Desktop.
What we say when we say F.. Yea! or F... No!
This file contains hidden or 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.{Comonad, Monad} | |
import scalaz.{Arrow, Contravariant, Profunctor} | |
import scalaz.{Lan, Ran} | |
object AnyAndNothingInstances { | |
// Monad | |
// https://twitter.com/runarorama/status/1085383309969014784 | |
type FYea[A] = Any | |
implicit val yeaMonad = new Monad[FYea] { | |
def bind[A, B](a: FYea[A])(f: A => FYea[B]): FYea[B] = a | |
def point[A](a: => A): FYea[A] = a | |
} | |
// Comonad | |
// https://twitter.com/runarorama/status/1085383912229142528 | |
type FNo[A] = Nothing | |
implicit val noComonad = new Comonad[FNo] { | |
def copoint[A](a: FNo[A]): A = a | |
def cobind[A, B](a: FNo[A])(f: FNo[A] => B): FNo[B] = a | |
def map[A, B](a: FNo[A])(f: A => B): FNo[B] = a | |
} | |
// both are Contravariant | |
val noContravariant = new Contravariant[FNo] { | |
def contramap[A, B](a: FNo[A])(f: B => A): FNo[B] = a | |
} | |
val yeaContravariant = new Contravariant[FYea] { | |
def contramap[A, B](a: FYea[A])(f: B => A): FYea[B] = a | |
} | |
// both are Profunctor | |
type FFYea[F,G] = Any | |
type FFNo[F,G] = Nothing | |
val yeaPro = new Profunctor[FFYea] { | |
def mapfst[A, B, C](a: FFYea[A, B])(f: C => A): FFYea[C, B] = a | |
def mapsnd[A, B, C](a: FFYea[A, B])(f: B => C): FFYea[A, C] = a | |
} | |
val noPro = new Profunctor[FFNo] { | |
def mapfst[A, B, C](a: FFNo[A, B])(f: C => A): FFNo[C, B] = a | |
def mapsnd[A, B, C](a: FFNo[A, B])(f: B => C): FFNo[A, C] = a | |
} | |
// Arrows | |
val yeaArrow = new Arrow[FFYea] { // TODO is it lawefull ? | |
def arr[A, B](f: A => B): FFYea[A, B] = f | |
def first[A, B, C](f: FFYea[A, B]): FFYea[(A, C), (B, C)] = f | |
def id[A]: FFYea[A, A] = identity _ | |
def compose[A, B, C](f: FFYea[B, C], g: FFYea[A, B]): FFYea[A, C] = f | |
} | |
// Kan extensions | |
def yeaKan[A] = new Ran[FYea, FYea, A] { | |
def apply[B](f: A => FYea[B]): FYea[B] = f | |
} | |
def yeaNoKan[A] = new Ran[FNo, FYea, A] { | |
def apply[B](f: A => FNo[B]): FYea[B] = f | |
} | |
def yeaLan[A] = new Lan[FNo, FYea, A] { // TODO does it makes sense ? | |
type I = Any | |
def v: FYea[I] = () | |
def f(f: FNo[I]): A = f | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment