Skip to content

Commit

Permalink
Merge pull request #7 from mblink/parallel-inst
Browse files Browse the repository at this point in the history
Provide `Parallel.Aux[RecProg, RecApProg]` instance
  • Loading branch information
mrdziuban authored Oct 4, 2024
2 parents 12969d5 + 9ac3367 commit f51d7b9
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 29 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [2.13.13, 3.3.3]
scala: [2.13.15, 3.3.4]
java: [temurin@8, temurin@11, temurin@17, temurin@21]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -64,6 +64,9 @@ jobs:
java-version: 21
cache: sbt

- name: Setup sbt
uses: sbt/setup-sbt@v1

- name: Check that workflows are up to date
run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck

Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Basic use is a pared down version of the manual process, with the following high
* Define DSLs as sealed families of case classes
* Define interpreters for DSLs as natural transformations
* Define the application Coproduct type for your composed DSLs
* Create an instance of ComposeFree[YourApplicationType] and import it
* Create an instance of `ComposeFree[YourApplicationType]` and import it

For example, let's say we wanted to combine a simple Console DSL with the Pure DSL
provided in the ComposeFree lib.
Expand Down Expand Up @@ -85,9 +85,9 @@ val prog1: compose.Composed[Unit] =
// implicitly converted to the correct coproduct member type
_ <- print(s)
} yield ()
// prog1: Free[[_$12 >: Nothing <: Any] => RecNode[Program, _$12], Unit] = FlatMapped(
// prog1: Free[[_$8 >: Nothing <: Any] => RecNode[Program, _$8], Unit] = FlatMapped(
// c = Suspend(a = EitherK(run = Right(value = pure(a = "Hello world!")))),
// f = repl.MdocSession$MdocApp$$Lambda/0x0000007003e00218@7f2657c7
// f = repl.MdocSession$MdocApp$$Lambda/0x000000e804891218@6687c3aa
// )

prog1.runWith(interp)
Expand Down Expand Up @@ -116,21 +116,21 @@ val prog2 = for {
_ <- print(s._1)
_ <- print(s._2)
} yield ()
// prog2: Free[[_$12 >: Nothing <: Any] => RecNode[Program, _$12], Unit] = FlatMapped(
// prog2: Free[[_$8 >: Nothing <: Any] => RecNode[Program, _$8], Unit] = FlatMapped(
// c = FlatMapped(
// c = FlatMapped(
// c = FlatMapped(
// c = FlatMapped(
// c = Suspend(a = EitherK(run = Right(value = pure(a = "Hello")))),
// f = cats.free.Free$$Lambda/0x0000007003e1e000@12fab5f3
// f = cats.free.Free$$Lambda/0x000000e8048b39e0@440856c6
// ),
// f = cats.StackSafeMonad$$Lambda/0x0000007003e1f668@4838c135
// f = cats.StackSafeMonad$$Lambda/0x000000e8048b72b0@335a7829
// ),
// f = cats.free.Free$$Lambda/0x0000007003e1e000@3217ad19
// f = cats.free.Free$$Lambda/0x000000e8048b39e0@3bc225c8
// ),
// f = cats.StackSafeMonad$$Lambda/0x0000007003e1f668@3c3c656e
// f = cats.StackSafeMonad$$Lambda/0x000000e8048b72b0@46f26d21
// ),
// f = repl.MdocSession$MdocApp$$Lambda/0x0000007003e1d0a8@7b2e1a37
// f = repl.MdocSession$MdocApp$$Lambda/0x000000e8048b50a8@40cabd5f
// )

prog2.runWith(interp)
Expand Down
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Global / onChangedBuildSource := ReloadOnSourceChanges

lazy val scala213 = "2.13.13"
lazy val scala3 = "3.3.3"
lazy val scala213 = "2.13.15"
lazy val scala3 = "3.3.4"
lazy val scalaVersions = Seq(scala213, scala3)

ThisBuild / crossScalaVersions := scalaVersions
Expand Down Expand Up @@ -49,12 +49,12 @@ lazy val commonSettings = Seq(
commonSettings
gitRelease := {}

lazy val catsVersion = "2.10.0"
lazy val catsVersion = "2.12.0"
lazy val catsCore = "org.typelevel" %% "cats-core" % catsVersion
lazy val catsFree = "org.typelevel" %% "cats-free" % catsVersion
lazy val catsLaws = "org.typelevel" %% "cats-laws" % catsVersion % Test
lazy val newtype = "io.estatico" %% "newtype" % "0.4.4"
lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.17.0" % Test
lazy val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.18.1" % Test

lazy val publishSettings = Seq(
publish / skip := false,
Expand Down
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))
}
}
}
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ComposeFree
# ComposeFree

ComposeFree is a small lib inspired by Runars
[Composable Application Architecture](http://functionaltalks.org/2014/11/23/runar-oli-bjarnason-free-monad/)
[Composable Application Architecture](https://youtu.be/M258zVn4m2M?si=NHCIN8RM2roOJAjv)
which minimizes the boilerplate required to build an application based on a coproduct of
Free DSLs.

Expand All @@ -18,7 +18,7 @@ Basic use is a pared down version of the manual process, with the following high
* Define DSLs as sealed families of case classes
* Define interpreters for DSLs as natural transformations
* Define the application Coproduct type for your composed DSLs
* Create an instance of ComposeFree[YourApplicationType] and import it
* Create an instance of `ComposeFree[YourApplicationType]` and import it

For example, let's say we wanted to combine a simple Console DSL with the Pure DSL
provided in the ComposeFree lib.
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.9
sbt.version=1.10.2
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.23.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.2")
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.0")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.24.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.6.1")
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.2")

resolvers += "bondlink-maven-repo" at "https://raw.githubusercontent.com/mblink/maven-repo/main"
addSbtPlugin("bondlink" % "sbt-git-publish" % "0.0.5")

0 comments on commit f51d7b9

Please sign in to comment.