package com.github.everpeace
import scalaz.{Monad, Comonad, Distributes}
object DistributiveLaws {
implicit def Tuple2EitherDistributes[A, E](implicit w: Comonad[({type λ[α] = (A, α)})#λ], m: Monad[({type λ[α] = Either[E, α]})#λ]): Distributes[({type λ[α] = (A, α)})#λ, ({type λ[α] = Either[E, α]})#λ]
= new Distributes[({type λ[α] = (A, α)})#λ, ({type λ[α] = Either[E, α]})#λ] {
def apply[C](f: (A, Either[E, C])): Either[E, (A, C)] = f match {
case (a, x) => x match {
case Left(e) => Left(e)
case Right(c) => Right((a, c))
}
}
}
}