Skip to content

Commit ef6c75c

Browse files
author
Luka Jacobowitz
committed
Add Either/Validated Parallel instance
1 parent 714b84d commit ef6c75c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cats.instances
2+
3+
import cats.data.Validated
4+
import cats.kernel.Semigroup
5+
import cats.syntax.either._
6+
import cats.{Applicative, Monad, Parallel, ~>}
7+
8+
9+
trait ParallelInstances {
10+
implicit def parEitherValidated[E: Semigroup] = new Parallel[Either[E, ?], Validated[E, ?]] {
11+
def applicative: Applicative[Validated[E, ?]] = Validated.catsDataApplicativeErrorForValidated
12+
13+
def sequential(implicit M: Monad[Either[E, ?]]): Validated[E, ?] ~> Either[E, ?] =
14+
λ[Validated[E, ?] ~> Either[E, ?]](_.toEither)
15+
16+
def parallel(implicit M: Monad[Either[E, ?]]): Either[E, ?] ~> Validated[E, ?] =
17+
λ[Either[E, ?] ~> Validated[E, ?]](_.toValidated)
18+
}
19+
}

core/src/main/scala/cats/syntax/all.scala

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ trait AllSyntax
3030
with MonoidSyntax
3131
with OptionSyntax
3232
with OrderSyntax
33+
with ParallelSyntax
3334
with PartialOrderSyntax
3435
with ProfunctorSyntax
3536
with ReducibleSyntax

0 commit comments

Comments
 (0)