11package cats
22package data
33
4+ import cats .arrow .FunctionK
45import cats .syntax .either ._
56import cats .syntax .option ._
67
@@ -155,6 +156,7 @@ object IorT extends IorTInstances {
155156 * scala> import cats.implicits._
156157 * scala> IorT.leftT[Option, Int]("err")
157158 * res0: cats.data.IorT[Option,String,Int] = IorT(Some(Left(err)))
159+
158160 * }}}
159161 */
160162 final def leftT [F [_], B ]: LeftTPartiallyApplied [F , B ] = new LeftTPartiallyApplied [F , B ]
@@ -412,6 +414,27 @@ private[data] abstract class IorTInstances extends IorTInstances1 {
412414
413415 implicit def catsDataMonoidForIorT [F [_], A , B ](implicit F : Monoid [F [Ior [A , B ]]]): Monoid [IorT [F , A , B ]] =
414416 new IorTMonoid [F , A , B ] { val F0 : Monoid [F [Ior [A , B ]]] = F }
417+
418+ implicit def catsDataParallelForIorTWithParallelEffect [M [_], F [_], E ]
419+ (implicit P : Parallel [M , F ], E : Semigroup [E ]): Parallel [IorT [M , E , ? ], IorT [F , E , ? ]] = new Parallel [IorT [M , E , ? ], IorT [F , E , ? ]]
420+ {
421+ val parallel : IorT [M , E , ? ] ~> IorT [F , E , ? ] = λ[IorT [M , E , ? ] ~> IorT [F , E , ? ]](fm => IorT (P .parallel(fm.value)))
422+ val sequential : IorT [F , E , ? ] ~> IorT [M , E , ? ] = λ[IorT [F , E , ? ] ~> IorT [M , E , ? ]](ff => IorT (P .sequential(ff.value)))
423+
424+ private [this ] val FA : Applicative [F ] = P .applicative
425+ private [this ] val IorA : Applicative [Ior [E , ? ]] = Parallel [Ior [E , ? ], Ior [E , ? ]].applicative
426+
427+ val applicative : Applicative [IorT [F , E , ? ]] = new Applicative [IorT [F , E , ? ]] {
428+ def pure [A ](a : A ): IorT [F , E , A ] = IorT .pure(a)(FA )
429+ def ap [A , B ](ff : IorT [F , E , A => B ])(fa : IorT [F , E , A ]): IorT [F , E , B ] =
430+ IorT (FA .map2(ff.value, fa.value)((f, a) => IorA .ap(f)(a)))
431+ }
432+
433+ lazy val monad : Monad [IorT [M , E , ? ]] = {
434+ implicit def underlyingMonadM : Monad [M ] = P .monad
435+ Monad [IorT [M , E , ? ]]
436+ }
437+ }
415438}
416439
417440private [data] abstract class IorTInstances1 extends IorTInstances2 {
@@ -426,6 +449,26 @@ private[data] abstract class IorTInstances1 extends IorTInstances2 {
426449 val A0 : Semigroup [A ] = A
427450 val F0 : Monad [F ] = F
428451 }
452+
453+ implicit def catsDataParallelForIorTWithSequentialEffect [F [_], E ]
454+ (implicit F : Monad [F ], E : Semigroup [E ]): Parallel [IorT [F , E , ? ], IorT [F , E , ? ]] = new Parallel [IorT [F , E , ? ], IorT [F , E , ? ]]
455+ {
456+ private [this ] val identityK : IorT [F , E , ? ] ~> IorT [F , E , ? ] = FunctionK .id
457+ private [this ] val underlyingParallel : Parallel [Ior [E , ? ], Ior [E , ? ]] =
458+ Parallel [Ior [E , ? ], Ior [E , ? ]]
459+
460+ def parallel : IorT [F , E , ? ] ~> IorT [F , E , ? ] = identityK
461+ def sequential : IorT [F , E , ? ] ~> IorT [F , E , ? ] = identityK
462+
463+ val applicative : Applicative [IorT [F , E , ? ]] = new Applicative [IorT [F , E , ? ]] {
464+ def pure [A ](a : A ): IorT [F , E , A ] = IorT .pure(a)
465+ def ap [A , B ](ff : IorT [F , E , A => B ])(fa : IorT [F , E , A ]): IorT [F , E , B ] =
466+ IorT (F .map2(ff.value, fa.value)((f, a) => underlyingParallel.applicative.ap(f)(a)))
467+ }
468+
469+ lazy val monad : Monad [IorT [F , E , ? ]] = Monad [IorT [F , E , ? ]]
470+ }
471+
429472}
430473
431474private [data] abstract class IorTInstances2 extends IorTInstances3 {
0 commit comments