Skip to content

Commit fb525a2

Browse files
committed
Get rid os simulacrum-scalafix's rudiments in Scala 3
1 parent aed26cc commit fb525a2

File tree

8 files changed

+20
-334
lines changed

8 files changed

+20
-334
lines changed

build.sbt

+8-17
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ val versions = Map(
1212
"paradise" -> "2.1.1",
1313
"bm4" -> "0.3.1",
1414
"scalatestplus-scalacheck" -> "3.2.11.0",
15-
"glass" -> "0.1.0",
16-
"simulacrum-scalafix-annotations" -> "0.5.4"
15+
"glass" -> "0.1.0"
1716
)
1817

1918
val scalaVersions = Seq("2.12.20", "2.13.14", "3.3.3")
@@ -35,11 +34,8 @@ lazy val morphling = (projectMatrix in file("core"))
3534
libraryDependencies ++= {
3635
(CrossVersion.partialVersion(scalaVersion.value): @unchecked) match {
3736
case Some((2, _)) =>
38-
Seq(
39-
"com.chuusai" %% "shapeless" % "2.3.3",
40-
)
41-
case Some((3, _)) => Seq()
42-
case Some((_, _)) => Seq()
37+
Seq("com.chuusai" %% "shapeless" % "2.3.3")
38+
case Some((3, _)) => Seq.empty[ModuleID]
4339
}
4440
}
4541
)
@@ -58,14 +54,12 @@ lazy val `morphling-scalacheck` = (projectMatrix in file("scalacheck"))
5854
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
5955
case Some((2, _)) =>
6056
Seq("io.github.leviysoft" %% "simulacrum" % versions("simulacrum"))
61-
case _ =>
62-
Seq("org.typelevel" %% "simulacrum-scalafix-annotations" % versions("simulacrum-scalafix-annotations"))
57+
case _ => Seq.empty[ModuleID]
6358
}),
6459
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
6560
case Some((2, y)) if y < 13 =>
6661
Seq(compilerPlugin("org.scalamacros" % "paradise" % versions("paradise") cross CrossVersion.full))
67-
case _ =>
68-
Seq.empty[ModuleID]
62+
case _ => Seq.empty[ModuleID]
6963
})
7064
)
7165

@@ -86,8 +80,7 @@ lazy val `morphling-circe` = (projectMatrix in file("circe"))
8680
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
8781
case Some((2, _)) =>
8882
Seq("io.github.leviysoft" %% "simulacrum" % versions("simulacrum"))
89-
case _ =>
90-
Seq("org.typelevel" %% "simulacrum-scalafix-annotations" % versions("simulacrum-scalafix-annotations"))
83+
case _ => Seq.empty[ModuleID]
9184
}),
9285
libraryDependencies += {
9386
(CrossVersion.partialVersion(scalaVersion.value): @unchecked) match {
@@ -127,8 +120,7 @@ lazy val `morphling-reactivemongo` = (projectMatrix in file("reactivemongo"))
127120
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
128121
case Some((2, _)) =>
129122
Seq("io.github.leviysoft" %% "simulacrum" % versions("simulacrum"))
130-
case _ =>
131-
Seq("org.typelevel" %% "simulacrum-scalafix-annotations" % versions("simulacrum-scalafix-annotations"))
123+
case _ => Seq.empty[ModuleID]
132124
}),
133125
libraryDependencies ++= {
134126
(CrossVersion.partialVersion(scalaVersion.value): @unchecked) match {
@@ -205,8 +197,7 @@ lazy val `morphling-tapir` = (projectMatrix in file("tapir"))
205197
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
206198
case Some((2, _)) =>
207199
Seq("io.github.leviysoft" %% "simulacrum" % versions("simulacrum"))
208-
case _ =>
209-
Seq("org.typelevel" %% "simulacrum-scalafix-annotations" % versions("simulacrum-scalafix-annotations"))
200+
case _ => Seq.empty[ModuleID]
210201
}),
211202
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
212203
case Some((2, y)) if y < 13 =>

circe/src/main/scala-3/morphling/circe/FromJson.scala

+1-45
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ import morphling.Schema.*
1010
import morphling.annotated.Schema.AnnotatedSchema
1111
import morphling.given
1212
import mouse.boolean.*
13-
import simulacrum.typeclass
1413

15-
import scala.annotation.implicitNotFound
16-
17-
@implicitNotFound("Could not find an instance of FromJson for ${S}")
18-
@typeclass
1914
trait FromJson[S[_]] extends Serializable {
2015
def decoder: S ~> Decoder
2116

@@ -25,6 +20,7 @@ trait FromJson[S[_]] extends Serializable {
2520
}
2621

2722
object FromJson {
23+
def apply[P[_]](using fj: FromJson[P]): FromJson[P] = fj
2824

2925
given [P[_]: FromJson]: FromJson[Schema[P, _]] =
3026
new FromJson[Schema[P, _]] {
@@ -129,44 +125,4 @@ object FromJson {
129125
)
130126
}
131127
}
132-
133-
/* ======================================================================== */
134-
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
135-
/* ======================================================================== */
136-
137-
/**
138-
* Summon an instance of [[FromJson]] for `S`.
139-
*/
140-
@inline def apply[S[_]](implicit instance: FromJson[S]): FromJson[S] = instance
141-
142-
object ops {
143-
implicit def toAllFromJsonOps[S[_], A](target: S[A])(implicit tc: FromJson[S]): AllOps[S, A] {
144-
type TypeClassType = FromJson[S]
145-
} = new AllOps[S, A] {
146-
type TypeClassType = FromJson[S]
147-
val self: S[A] = target
148-
val typeClassInstance: TypeClassType = tc
149-
}
150-
}
151-
trait Ops[S[_], A] extends Serializable {
152-
type TypeClassType <: FromJson[S]
153-
def self: S[A]
154-
val typeClassInstance: TypeClassType
155-
}
156-
trait AllOps[S[_], A] extends Ops[S, A]
157-
trait ToFromJsonOps extends Serializable {
158-
implicit def toFromJsonOps[S[_], A](target: S[A])(implicit tc: FromJson[S]): Ops[S, A] {
159-
type TypeClassType = FromJson[S]
160-
} = new Ops[S, A] {
161-
type TypeClassType = FromJson[S]
162-
val self: S[A] = target
163-
val typeClassInstance: TypeClassType = tc
164-
}
165-
}
166-
object nonInheritedOps extends ToFromJsonOps
167-
168-
/* ======================================================================== */
169-
/* END OF SIMULACRUM-MANAGED CODE */
170-
/* ======================================================================== */
171-
172128
}

circe/src/main/scala-3/morphling/circe/ToFilter.scala

+2-48
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ import morphling.Schema.Schema
1212
import morphling.annotated.Schema.AnnotatedSchema
1313
import morphling.given
1414
import mouse.option.*
15-
import simulacrum.typeclass
1615

17-
import scala.annotation.implicitNotFound
18-
19-
/**
20-
* Allows to filter Json via specific schema
21-
*/
22-
@implicitNotFound("Could not find an instance of ToFilter for ${S}")
23-
@typeclass
2416
trait ToFilter[S[_]] extends Serializable {
2517
def filter: S ~> Const[Json => Option[Json], *]
2618

@@ -31,6 +23,8 @@ object ToFilter {
3123
type Subset[T] = T => Option[T]
3224
type JsonFilter[T] = Const[Subset[Json], T]
3325

26+
def apply[P[_]](using tf: ToFilter[P]): ToFilter[P] = tf
27+
3428
given [P[_]: ToFilter]: ToFilter[Schema[P, _]] =
3529
new ToFilter[Schema[P, _]] {
3630
override val filter: Schema[P, _] ~> JsonFilter = new (Schema[P, _] ~> JsonFilter) {
@@ -127,44 +121,4 @@ object ToFilter {
127121
override def combine(x: Subset[Json], y: Subset[Json]): Subset[Json] =
128122
x &&& y andThen { case (lhs, rhs) => lhs |+| rhs }
129123
}
130-
131-
/* ======================================================================== */
132-
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
133-
/* ======================================================================== */
134-
135-
/**
136-
* Summon an instance of [[ToFilter]] for `S`.
137-
*/
138-
@inline def apply[S[_]](implicit instance: ToFilter[S]): ToFilter[S] = instance
139-
140-
object ops {
141-
implicit def toAllToFilterOps[S[_], A](target: S[A])(implicit tc: ToFilter[S]): AllOps[S, A] {
142-
type TypeClassType = ToFilter[S]
143-
} = new AllOps[S, A] {
144-
type TypeClassType = ToFilter[S]
145-
val self: S[A] = target
146-
val typeClassInstance: TypeClassType = tc
147-
}
148-
}
149-
trait Ops[S[_], A] extends Serializable {
150-
type TypeClassType <: ToFilter[S]
151-
def self: S[A]
152-
val typeClassInstance: TypeClassType
153-
}
154-
trait AllOps[S[_], A] extends Ops[S, A]
155-
trait ToToFilterOps extends Serializable {
156-
implicit def toToFilterOps[S[_], A](target: S[A])(implicit tc: ToFilter[S]): Ops[S, A] {
157-
type TypeClassType = ToFilter[S]
158-
} = new Ops[S, A] {
159-
type TypeClassType = ToFilter[S]
160-
val self: S[A] = target
161-
val typeClassInstance: TypeClassType = tc
162-
}
163-
}
164-
object nonInheritedOps extends ToToFilterOps
165-
166-
/* ======================================================================== */
167-
/* END OF SIMULACRUM-MANAGED CODE */
168-
/* ======================================================================== */
169-
170124
}

circe/src/main/scala-3/morphling/circe/ToJson.scala

+1-45
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@ import morphling.*
1010
import morphling.Schema.*
1111
import morphling.annotated.Schema.AnnotatedSchema
1212
import mouse.option.*
13-
import simulacrum.typeclass
1413

15-
import scala.annotation.implicitNotFound
16-
17-
@implicitNotFound("Could not find an instance of ToJson for ${S}")
18-
@typeclass
1914
trait ToJson[S[_]] extends Serializable {
2015
def encoder: S ~> Encoder
2116

2217
extension [F[_], A](fa: F[A])(using TJ: ToJson[F]) def encoder: Encoder[A] = TJ.encoder(fa)
2318
}
2419

2520
object ToJson {
21+
def apply[P[_]](using tj: ToJson[P]): ToJson[P] = tj
2622

2723
given [P[_]: ToJson]: ToJson[Schema[P, _]] =
2824
new ToJson[Schema[P, _]] {
@@ -109,44 +105,4 @@ object ToJson {
109105
p.run.fold(ToJson[P].encoder(_), ToJson[Q].encoder(_))
110106
}
111107
}
112-
113-
/* ======================================================================== */
114-
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
115-
/* ======================================================================== */
116-
117-
/**
118-
* Summon an instance of [[ToJson]] for `S`.
119-
*/
120-
@inline def apply[S[_]](implicit instance: ToJson[S]): ToJson[S] = instance
121-
122-
object ops {
123-
implicit def toAllToJsonOps[S[_], A](target: S[A])(implicit tc: ToJson[S]): AllOps[S, A] {
124-
type TypeClassType = ToJson[S]
125-
} = new AllOps[S, A] {
126-
type TypeClassType = ToJson[S]
127-
val self: S[A] = target
128-
val typeClassInstance: TypeClassType = tc
129-
}
130-
}
131-
trait Ops[S[_], A] extends Serializable {
132-
type TypeClassType <: ToJson[S]
133-
def self: S[A]
134-
val typeClassInstance: TypeClassType
135-
}
136-
trait AllOps[S[_], A] extends Ops[S, A]
137-
trait ToToJsonOps extends Serializable {
138-
implicit def toToJsonOps[S[_], A](target: S[A])(implicit tc: ToJson[S]): Ops[S, A] {
139-
type TypeClassType = ToJson[S]
140-
} = new Ops[S, A] {
141-
type TypeClassType = ToJson[S]
142-
val self: S[A] = target
143-
val typeClassInstance: TypeClassType = tc
144-
}
145-
}
146-
object nonInheritedOps extends ToToJsonOps
147-
148-
/* ======================================================================== */
149-
/* END OF SIMULACRUM-MANAGED CODE */
150-
/* ======================================================================== */
151-
152108
}

reactivemongo/src/main/scala-3/morphling/reactivemongo/FromBson.scala

+2-45
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ import morphling.{Absent, Alt, Constant, HAlgebra, HEnvT, HFix, IsoSchema, OneOf
1010
import mouse.boolean.*
1111
import mouse.option.*
1212
import reactivemongo.api.bson.*
13-
import simulacrum.typeclass
1413

15-
import scala.annotation.implicitNotFound
16-
17-
@implicitNotFound("Could not find an instance of FromBson for ${S}")
18-
@typeclass
1914
trait FromBson[S[_]] extends Serializable {
2015
def reader: S ~> BSONReader
2116

@@ -25,6 +20,8 @@ trait FromBson[S[_]] extends Serializable {
2520
}
2621

2722
object FromBson {
23+
def apply[P[_]](using fb: FromBson[P]): FromBson[P] = fb
24+
2825
given [P[_]: FromBson]: FromBson[Schema[P, _]] =
2926
new FromBson[Schema[P, _]] {
3027
override val reader: Schema[P, _] ~> BSONReader = new (Schema[P, _] ~> BSONReader) {
@@ -139,44 +136,4 @@ object FromBson {
139136
)
140137
}
141138
}
142-
143-
/* ======================================================================== */
144-
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
145-
/* ======================================================================== */
146-
147-
/**
148-
* Summon an instance of [[FromBson]] for `S`.
149-
*/
150-
@inline def apply[S[_]](implicit instance: FromBson[S]): FromBson[S] = instance
151-
152-
object ops {
153-
implicit def toAllFromBsonOps[S[_], A](target: S[A])(implicit tc: FromBson[S]): AllOps[S, A] {
154-
type TypeClassType = FromBson[S]
155-
} = new AllOps[S, A] {
156-
type TypeClassType = FromBson[S]
157-
val self: S[A] = target
158-
val typeClassInstance: TypeClassType = tc
159-
}
160-
}
161-
trait Ops[S[_], A] extends Serializable {
162-
type TypeClassType <: FromBson[S]
163-
def self: S[A]
164-
val typeClassInstance: TypeClassType
165-
}
166-
trait AllOps[S[_], A] extends Ops[S, A]
167-
trait ToFromBsonOps extends Serializable {
168-
implicit def toFromBsonOps[S[_], A](target: S[A])(implicit tc: FromBson[S]): Ops[S, A] {
169-
type TypeClassType = FromBson[S]
170-
} = new Ops[S, A] {
171-
type TypeClassType = FromBson[S]
172-
val self: S[A] = target
173-
val typeClassInstance: TypeClassType = tc
174-
}
175-
}
176-
object nonInheritedOps extends ToFromBsonOps
177-
178-
/* ======================================================================== */
179-
/* END OF SIMULACRUM-MANAGED CODE */
180-
/* ======================================================================== */
181-
182139
}

0 commit comments

Comments
 (0)