Skip to content

Commit

Permalink
Share ComposeNode definition, provide Parallel instance between `…
Browse files Browse the repository at this point in the history
…RecProg` and `RecApProg`.
  • Loading branch information
mrdziuban committed Oct 4, 2024
1 parent 495da1b commit 50fa4d4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 0 additions & 4 deletions core/src/main/scala-2/composefree/PackageCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import cats.~>
import cats.data.EitherK
import cats.free.{Free, FreeApplicative}

sealed trait ComposeNode[M[_], A]
final case class MNode[M[_], A](run: Free[RecNode[M, *], A]) extends ComposeNode[M, A]
final case class ANode[M[_], A](run: FreeApplicative[RecNode[M, *], A]) extends ComposeNode[M, A]

trait PackageCompat {
final type RecNode[M[_], A] = EitherK[ComposeNode[M, *], M, A]
object RecNode {
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/scala-3/composefree/PackageCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ package composefree
import cats.~>
import cats.free.{Free, FreeApplicative}

sealed trait ComposeNode[M[_], A]
final case class MNode[M[_], A](run: RecProg[M, A]) extends ComposeNode[M, A]
final case class ANode[M[_], A](run: FreeApplicative[RecNode[M, *], A]) extends ComposeNode[M, A]

type RecNode[M[_], A] = ComposeNode[M, A] | M[A]
object RecNode {
inline def fold[M[_], F[_], A](n: RecNode[M, A])(c: ComposeNode[M, *] ~> F, m: M ~> F): F[A] =
Expand Down
22 changes: 22 additions & 0 deletions core/src/main/scala/composefree/ComposeNode.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package composefree

import cats.{~>, Applicative, Monad, Parallel}

sealed trait ComposeNode[M[_], A]
final case class MNode[M[_], A](run: RecProg[M, A]) extends ComposeNode[M, A]
final case class ANode[M[_], A](run: RecApProg[M, A]) extends ComposeNode[M, A]

object ComposeNode {
implicit def recProgParallel[M[_]]: Parallel.Aux[RecProg[M, *], RecApProg[M, *]] =
new Parallel[RecProg[M, *]] {
type F[a] = RecApProg[M, a]
val applicative = Applicative[RecApProg[M, *]]
val monad = Monad[RecProg[M, *]]
val parallel = new (RecProg[M, *] ~> RecApProg[M, *]) {
def apply[A](p: RecProg[M, A]): RecApProg[M, A] = RecApProg.liftCN(MNode(p))
}
val sequential = new (RecApProg[M, *] ~> RecProg[M, *]) {
def apply[A](p: RecApProg[M, A]): RecProg[M, A] = RecProg.liftCN(ANode(p))
}
}
}

0 comments on commit 50fa4d4

Please sign in to comment.