Skip to content

Commit

Permalink
update magnolia
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Apr 27, 2024
1 parent 9f68251 commit 0ab57e5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
with:
java-version: 8
distribution: temurin
- run: sbt -v scalafmtSbtCheck scalafmtCheckAll "+ scalapropsMagnoliaJVM/test" "+ scalapropsMagnoliaJS/test"
- run: sbt -v scalafmtSbtCheck scalafmtCheckAll "+ scalapropsMagnoliaJVM/test"
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ lazy val commonSettings = nocomma {
)
}

lazy val scalapropsMagnolia = crossProject(JVMPlatform, JSPlatform)
lazy val scalapropsMagnolia = crossProject(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("."))
.settings(
Expand Down Expand Up @@ -109,7 +109,8 @@ lazy val scalapropsMagnolia = crossProject(JVMPlatform, JSPlatform)
}
scalapropsVersion := "0.9.1"
libraryDependencies ++= Seq(
"com.propensive" %%% "magnolia" % "0.14.5",
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"com.softwaremill.magnolia1_2" %% "magnolia" % "1.1.9",
"com.github.scalaprops" %%% "scalaprops-gen" % scalapropsVersion.value,
"com.github.scalaprops" %%% "scalaprops" % scalapropsVersion.value % "test"
)
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/scalaprops/ScalapropsMagnoliaCogen.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package scalaprops

import magnolia.{CaseClass, Magnolia, SealedTrait}
import magnolia1.{CaseClass, Magnolia, SealedTrait}

object ScalapropsMagnoliaCogen {
type Typeclass[T] = scalaprops.Cogen[T]

def combine[T](ctx: CaseClass[Typeclass, T]): Typeclass[T] =
def join[T](ctx: CaseClass[Typeclass, T]): Typeclass[T] =
new Cogen[T] {
def cogen[B](t: T, g: CogenState[B]) = {
ctx.parameters.zipWithIndex.foldLeft(g) { case (state, (p, i)) =>
Expand All @@ -14,7 +14,7 @@ object ScalapropsMagnoliaCogen {
}
}

def dispatch[T](ctx: SealedTrait[Typeclass, T]): Typeclass[T] =
def split[T](ctx: SealedTrait[Typeclass, T]): Typeclass[T] =
new Cogen[T] {
def cogen[B](t: T, g: CogenState[B]) = {
val index = ctx.subtypes.indexWhere(_.cast.isDefinedAt(t))
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/scalaprops/ScalapropsMagnoliaGen.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package scalaprops

import magnolia.{CaseClass, Magnolia, SealedTrait}
import magnolia1.{CaseClass, Magnolia, SealedTrait}

object ScalapropsMagnoliaGen {
type Typeclass[T] = scalaprops.Gen[T]

def combine[T](ctx: CaseClass[Gen, T]): Gen[T] =
def join[T](ctx: CaseClass[Gen, T]): Gen[T] =
Gen.gen[T] { (size, rand) =>
var r = rand
val result = ctx.construct { p =>
Expand All @@ -17,7 +17,7 @@ object ScalapropsMagnoliaGen {
r -> result
}

def dispatch[T](ctx: SealedTrait[Gen, T]): Gen[T] = {
def split[T](ctx: SealedTrait[Gen, T]): Gen[T] = {
val gs: Seq[Gen[T]] = ctx.subtypes.map { x => x.typeclass.asInstanceOf[Gen[T]] }
Gen.choose(0, gs.size - 1).flatMap(gs)
}
Expand Down

0 comments on commit 0ab57e5

Please sign in to comment.