Skip to content

Commit

Permalink
Add Either/Validated Parallel instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Jacobowitz committed Aug 21, 2017
1 parent 714b84d commit c5fc3ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/src/main/scala/cats/instances/parallel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cats.instances

import cats.data.Validated
import cats.kernel.Semigroup
import cats.syntax.either._
import cats.{Applicative, Monad, Parallel, ~>}


trait ParallelInstances {
implicit def parEitherValidated[E: Semigroup]: Parallel[Either[E, ?], Validated[E, ?]] = new Parallel[Either[E, ?], Validated[E, ?]] {
def applicative: Applicative[Validated[E, ?]] = Validated.catsDataApplicativeErrorForValidated

def sequential(implicit M: Monad[Either[E, ?]]): Validated[E, ?] ~> Either[E, ?] =
λ[Validated[E, ?] ~> Either[E, ?]](_.toEither)

def parallel(implicit M: Monad[Either[E, ?]]): Either[E, ?] ~> Validated[E, ?] =
λ[Either[E, ?] ~> Validated[E, ?]](_.toValidated)
}
}
1 change: 1 addition & 0 deletions core/src/main/scala/cats/syntax/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ trait AllSyntax
with MonoidSyntax
with OptionSyntax
with OrderSyntax
with ParallelSyntax
with PartialOrderSyntax
with ProfunctorSyntax
with ReducibleSyntax
Expand Down

0 comments on commit c5fc3ee

Please sign in to comment.