Skip to content

Commit

Permalink
fix free parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
kitlangton committed Feb 6, 2022
1 parent 83ecae8 commit 0fc6bd9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/test/scala/parallelfor/test/FreeParallel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ sealed trait FreeParallel[-R, +E, +A] extends Product with Serializable { self =

def traceImpl: (Trace, A)

def flatMap[R1 <: R, E1 >: E, B](f: A => FreeParallel[R1, E1, B])(implicit
dummyImplicit: DummyImplicit
): FreeParallel[R1, E1, B] =
def zipPar[R1 <: R, E1 >: E, B](that: FreeParallel[R1, E1, B])(implicit
zippable: Zippable[A, B]
): FreeParallel[R1, E1, zippable.Out] =
FreeParallel.ZipPar(self, that).map { case (a, b) => zippable.zip(a, b) }

def flatMap[R1 <: R, E1 >: E, B](f: A => FreeParallel[R1, E1, B]): FreeParallel[R1, E1, B] =
FreeParallel.FlatMap(this, f)

def map[R1 <: R, E1 >: E, B](f: A => B)(implicit dummyImplicit: DummyImplicit): FreeParallel[R1, E1, B] =
def map[B](f: A => B): FreeParallel[R, E, B] =
FreeParallel.Map(this, f)
}

object FreeParallel {
def effect[A](a: A): FreeParallel[Any, Nothing, A] =
FreeParallel.Succeed(a)

final case class ZipPar[R, E, A, B](left: FreeParallel[R, E, A], right: FreeParallel[R, E, B])
final case class ZipPar[-R, +E, +A, +B](left: FreeParallel[R, E, A], right: FreeParallel[R, E, B])
extends FreeParallel[R, E, (A, B)] {
override def traceImpl: (Trace, (A, B)) = {
val (lhsTrace, lhsValue) = left.traceImpl
Expand All @@ -36,7 +39,7 @@ object FreeParallel {
}
}

final case class FlatMap[R, E, A, B](fa: FreeParallel[R, E, A], f: A => FreeParallel[R, E, B])
final case class FlatMap[-R, +E, A, +B](fa: FreeParallel[R, E, A], f: A => FreeParallel[R, E, B])
extends FreeParallel[R, E, B] {

override def traceImpl: (Trace, B) = {
Expand All @@ -47,7 +50,7 @@ object FreeParallel {
}
}

final case class Map[R, E, A, B](fa: FreeParallel[R, E, A], f: A => B) extends FreeParallel[R, E, B] {
final case class Map[-R, +E, A, +B](fa: FreeParallel[R, E, A], f: A => B) extends FreeParallel[R, E, B] {

override def traceImpl: (Trace, B) = {
val (faTrace, faValue) = fa.traceImpl
Expand Down

0 comments on commit 0fc6bd9

Please sign in to comment.