Skip to content

Commit

Permalink
Move appError instance to Parallel companion object
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Aug 29, 2017
1 parent e72b087 commit 7aa9384
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 16 additions & 0 deletions core/src/main/scala/cats/Parallel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,20 @@ object Parallel extends ParallelArityFunctions {
(ma: M[A], mb: M[B])
(implicit P: Parallel[M, F]): M[Z] =
Monad[M].map(parProduct(ma, parProduct(mb, ff))) { case (a, (b, f)) => f(a, b) }

def applicativeError[F[_], M[_], E]
(implicit P: Parallel[M, F], E: MonadError[M, E]): ApplicativeError[F, E] = new ApplicativeError[F, E] {

def raiseError[A](e: E): F[A] =
P.parallel.apply(MonadError[M, E].raiseError(e))

def handleErrorWith[A](fa: F[A])(f: (E) => F[A]): F[A] = {
val ma = MonadError[M, E].handleErrorWith(P.sequential.apply(fa))(f andThen P.sequential.apply)
P.parallel.apply(ma)
}

def pure[A](x: A): F[A] = P.applicative.pure(x)

def ap[A, B](ff: F[(A) => B])(fa: F[A]): F[B] = P.applicative.ap(ff)(fa)
}
}
16 changes: 0 additions & 16 deletions core/src/main/scala/cats/instances/parallel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ trait ParallelInstances {
λ[Either[E, ?] ~> Validated[E, ?]](_.toValidated)
}

implicit def catsApplicativeErrorForParallelMonadError[F[_], M[_], E]
(implicit P: Parallel[M, F], E: MonadError[M, E]): ApplicativeError[F, E] = new ApplicativeError[F, E] {

def raiseError[A](e: E): F[A] =
P.parallel.apply(MonadError[M, E].raiseError(e))

def handleErrorWith[A](fa: F[A])(f: (E) => F[A]): F[A] = {
val ma = MonadError[M, E].handleErrorWith(P.sequential.apply(fa))(f andThen P.sequential.apply)
P.parallel.apply(ma)
}

def pure[A](x: A): F[A] = P.applicative.pure(x)

def ap[A, B](ff: F[(A) => B])(fa: F[A]): F[B] = P.applicative.ap(ff)(fa)
}

implicit def catsParallelForOptionTNestedOption[F[_], M[_]: Monad]
(implicit P: Parallel[M, F]): Parallel[OptionT[M, ?], Nested[F, Option, ?]] = new Parallel[OptionT[M, ?], Nested[F, Option, ?]] {
implicit val appF: Applicative[F] = P.applicative
Expand Down

0 comments on commit 7aa9384

Please sign in to comment.