Skip to content

Commit

Permalink
Work around binary compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Apr 26, 2019
1 parent 8db9474 commit 49b513d
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions core/shared/src/main/scala/cats/effect/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,29 @@ private[effect] abstract class IOParallelNewtype
* for more details.
*/
object Par extends IONewtype

private[effect] def ioParCommutativeApplicative(implicit cs: ContextShift[IO]): CommutativeApplicative[IO.Par] =
new CommutativeApplicative[IO.Par] {
import IO.Par.{unwrap, apply => par}

final override def pure[A](x: A): IO.Par[A] =
par(IO.pure(x))
final override def map2[A, B, Z](fa: IO.Par[A], fb: IO.Par[B])(f: (A, B) => Z): IO.Par[Z] =
par(IOParMap(cs, unwrap(fa), unwrap(fb))(f))
final override def ap[A, B](ff: IO.Par[A => B])(fa: IO.Par[A]): IO.Par[B] =
map2(ff, fa)(_(_))
final override def product[A, B](fa: IO.Par[A], fb: IO.Par[B]): IO.Par[(A, B)] =
map2(fa, fb)((_, _))
final override def map[A, B](fa: IO.Par[A])(f: A => B): IO.Par[B] =
par(unwrap(fa).map(f))
final override def unit: IO.Par[Unit] =
par(IO.unit)
}
}

private[effect] abstract class IOLowPriorityInstances extends IOParallelNewtype {
implicit def parApplicative(implicit cs: ContextShift[IO]): Applicative[IO.Par] = ioParCommutativeApplicative

private[effect] class IOSemigroup[A: Semigroup] extends Semigroup[IO[A]] {
def combine(ioa1: IO[A], ioa2: IO[A]) =
ioa1.flatMap(a1 => ioa2.map(a2 => Semigroup[A].combine(a1, a2)))
Expand Down Expand Up @@ -796,23 +816,7 @@ private[effect] abstract class IOLowPriorityInstances extends IOParallelNewtype
}

private[effect] abstract class IOInstances extends IOLowPriorityInstances {

implicit def parApplicative(implicit cs: ContextShift[IO]): CommutativeApplicative[IO.Par] = new CommutativeApplicative[IO.Par] {
import IO.Par.{unwrap, apply => par}

final override def pure[A](x: A): IO.Par[A] =
par(IO.pure(x))
final override def map2[A, B, Z](fa: IO.Par[A], fb: IO.Par[B])(f: (A, B) => Z): IO.Par[Z] =
par(IOParMap(cs, unwrap(fa), unwrap(fb))(f))
final override def ap[A, B](ff: IO.Par[A => B])(fa: IO.Par[A]): IO.Par[B] =
map2(ff, fa)(_(_))
final override def product[A, B](fa: IO.Par[A], fb: IO.Par[B]): IO.Par[(A, B)] =
map2(fa, fb)((_, _))
final override def map[A, B](fa: IO.Par[A])(f: A => B): IO.Par[B] =
par(unwrap(fa).map(f))
final override def unit: IO.Par[Unit] =
par(IO.unit)
}
implicit def parCommutativeApplicative(implicit cs: ContextShift[IO]): CommutativeApplicative[IO.Par] = ioParCommutativeApplicative

implicit def ioConcurrentEffect(implicit cs: ContextShift[IO]): ConcurrentEffect[IO] =
new IOEffect with ConcurrentEffect[IO] {
Expand Down

0 comments on commit 49b513d

Please sign in to comment.