- Implement Functor[Try].
implicit val tryFunctor: Functor[Try] = new Functor[Try] {
override def map[A, B](in: Try[A])(f: A => B): Try[B] = in.map(f)
override def mapC[A, B](f: A => B): Try[A] => Try[B] = fa => map(fa)(f)
}
- Implement Applicative[Try].
implicit val tryApplicative: Applicative[Try] = new Applicative[Try] {
override def apply[A, B](a: Try[A])(f: Try[A => B]): Try[B] = (a, f) match {
case (Success(a), Success(f)) => Try(f(a))
case (Failure(ex), _) => Failure(ex)
case (_, Failure(ex)) => Failure(ex)
}
override def unit[A](a: => A): Try[A] = Success(a)
}
- Implement Applicative[Either].
implicit def eitherApplicative[L] = new Applicative[({ type T[A] = Either[L, A] })#T] {
override def apply[A, B](a: Either[L, A])(f: Either[L, A => B]): Either[L, B] = (a, f) match {
case (Right(a), Right(f)) => Right...