Skip to content

Commit

Permalink
Merge pull request #348 from joan38/scala3
Browse files Browse the repository at this point in the history
Upgrade to Scala 3 and Monocle 3
  • Loading branch information
zarthross authored Sep 20, 2023
2 parents faf9a6a + 75c028f commit 896a1e4
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 123 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.17, 2.13.12]
scala: [2.13.12, 3.3.1]
java: [temurin@11, temurin@17]
project: [rootJS, rootJVM]
exclude:
- scala: 2.12.17
- scala: 3.3.1
java: temurin@17
- project: rootJS
java: temurin@17
Expand Down Expand Up @@ -187,42 +187,42 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.12.17, rootJS)
- name: Download target directories (2.13.12, rootJS)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.17-rootJS
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.12-rootJS

- name: Inflate target directories (2.12.17, rootJS)
- name: Inflate target directories (2.13.12, rootJS)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.12.17, rootJVM)
- name: Download target directories (2.13.12, rootJVM)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.17-rootJVM
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.12-rootJVM

- name: Inflate target directories (2.12.17, rootJVM)
- name: Inflate target directories (2.13.12, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.12, rootJS)
- name: Download target directories (3.3.1, rootJS)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.12-rootJS
name: target-${{ matrix.os }}-${{ matrix.java }}-3.3.1-rootJS

- name: Inflate target directories (2.13.12, rootJS)
- name: Inflate target directories (3.3.1, rootJS)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.12, rootJVM)
- name: Download target directories (3.3.1, rootJVM)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.12-rootJVM
name: target-${{ matrix.os }}-${{ matrix.java }}-3.3.1-rootJVM

- name: Inflate target directories (2.13.12, rootJVM)
- name: Inflate target directories (3.3.1, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ This project provides tools for working with JSON values using [circe][circe] an
it was promoted to its own project in order to decouple its releases (and the Scala versions it
is cross-published for) from the main circe modules.

## Versioning

This library releases at a different cadence than [Circe], any apparent relationship between the [Circe] version numbers
and circe-optics version numbers are a coincidence and NOT intentional.
Please use the following table for determining capability with the corresponding [Circe] versions.

| Circe Optics Version | Circe | Monocle | Scala 2 | Scala 3 | Scala JVM | Scala.JS |
|----------------------|--------|---------|---------|---------|-----------|----------|
| 0.15.0 and later | 0.14.x | 3.x |||||
| 0.14.1 | 0.14.x | 2.x |||||
| 0.14.0 | 0.14.x | 2.x |||||

## Contributors and participation

This project supports the Scala [code of conduct][code-of-conduct] and we want
Expand All @@ -35,4 +47,4 @@ limitations under the License.
[circe]: https://github.com/circe/circe
[code-of-conduct]: https://www.scala-lang.org/conduct.html
[contributing]: https://circe.github.io/circe/contributing.html
[monocle]: https://github.com/julien-truffaut/Monocle
[monocle]: https://github.com/optics-dev/Monocle
19 changes: 11 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
val Versions = new {
val circe = "0.14.5"
val monocle = "2.1.0"
val monocle = "3.2.0"
val discipline = "2.2.0"
val scalaTestPlus = "3.2.11.0"

val previousCirceOptics = "0.14.1"

val scala212 = "2.12.17"
val scala213 = "2.13.12"
val scala3 = "3.3.1"

val scalaVersions = Seq(scala212, scala213)
val scalaVersions = Seq(scala213, scala3)
}

ThisBuild / crossScalaVersions := Versions.scalaVersions
ThisBuild / scalaVersion := Versions.scala213
ThisBuild / tlFatalWarningsInCi := false //TODO: ... fix this someday
val semVerRegex = """(\d+\.\d+\.)(\d+)(?:-SNAPSHOT)?""".r

lazy val root = tlCrossRootProject.aggregate(optics)

Expand All @@ -25,10 +24,14 @@ lazy val optics = crossProject(JVMPlatform, JSPlatform)
.settings(
name := "circe-optics",
description := "Monocle lenses and other tools for working with JSON values",
mimaPreviousArtifacts := Set("io.circe" %% "circe-optics" % Versions.previousCirceOptics),
mimaPreviousArtifacts := (version.value match {
case semVerRegex(majorMinor, "0") => Set.empty
case semVerRegex(majorMinor, patch) => Set("io.circe" %% "circe-optics" % (majorMinor + (patch.toInt - 1)))
}),
libraryDependencies ++= Seq(
"com.github.julien-truffaut" %%% "monocle-core" % Versions.monocle,
"com.github.julien-truffaut" %%% "monocle-law" % Versions.monocle % Test,
"dev.optics" %%% "monocle-core" % Versions.monocle,
"dev.optics" %%% "monocle-macro" % Versions.monocle % Test,
"dev.optics" %%% "monocle-law" % Versions.monocle % Test,
"io.circe" %%% "circe-core" % Versions.circe,
"io.circe" %%% "circe-generic" % Versions.circe % Test,
"io.circe" %%% "circe-testing" % Versions.circe % Test,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ trait JsonNumberOptics {
)
}

final object JsonNumberOptics extends JsonNumberOptics {
object JsonNumberOptics extends JsonNumberOptics {
private[optics] def isNegativeZero(jn: JsonNumber): Boolean = jn.toBiggerDecimal.isNegativeZero
}
8 changes: 4 additions & 4 deletions optics/src/main/scala/io/circe/optics/JsonObjectOptics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ trait JsonObjectOptics extends ListInstances {

implicit final lazy val jsonObjectEach: Each[JsonObject, Json] = new Each[JsonObject, Json] {
final def each: Traversal[JsonObject, Json] = new Traversal[JsonObject, Json] {
final def modifyF[F[_]](f: Json => F[Json])(from: JsonObject)(implicit
final def modifyA[F[_]](f: Json => F[Json])(from: JsonObject)(implicit
F: Applicative[F]
): F[JsonObject] = from.traverse(f)
}
Expand All @@ -60,8 +60,8 @@ trait JsonObjectOptics extends ListInstances {

implicit final lazy val jsonObjectFilterIndex: FilterIndex[JsonObject, String, Json] =
new FilterIndex[JsonObject, String, Json] {
final def filterIndex(p: String => Boolean) = new Traversal[JsonObject, Json] {
final def modifyF[F[_]](f: Json => F[Json])(from: JsonObject)(implicit
final def filterIndex(p: String => Boolean): Traversal[JsonObject, Json] = new Traversal[JsonObject, Json] {
final def modifyA[F[_]](f: Json => F[Json])(from: JsonObject)(implicit
F: Applicative[F]
): F[JsonObject] =
F.map(
Expand All @@ -75,4 +75,4 @@ trait JsonObjectOptics extends ListInstances {
implicit final lazy val jsonObjectIndex: Index[JsonObject, String, Json] = Index.fromAt
}

final object JsonObjectOptics extends JsonObjectOptics
object JsonObjectOptics extends JsonObjectOptics
22 changes: 11 additions & 11 deletions optics/src/main/scala/io/circe/optics/JsonOptics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ import monocle.function.Plated
trait JsonOptics {
final lazy val jsonNull: Prism[Json, Unit] = Prism[Json, Unit](j => if (j.isNull) Some(()) else None)(_ => Json.Null)
final lazy val jsonBoolean: Prism[Json, Boolean] = Prism[Json, Boolean](_.asBoolean)(Json.fromBoolean)
final lazy val jsonBigDecimal: Prism[Json, BigDecimal] = jsonNumber.composePrism(jsonNumberBigDecimal)
final lazy val jsonBigInt: Prism[Json, BigInt] = jsonNumber.composePrism(jsonNumberBigInt)
final lazy val jsonLong: Prism[Json, Long] = jsonNumber.composePrism(jsonNumberLong)
final lazy val jsonInt: Prism[Json, Int] = jsonNumber.composePrism(jsonNumberInt)
final lazy val jsonShort: Prism[Json, Short] = jsonNumber.composePrism(jsonNumberShort)
final lazy val jsonByte: Prism[Json, Byte] = jsonNumber.composePrism(jsonNumberByte)
final lazy val jsonBigDecimal: Prism[Json, BigDecimal] = jsonNumber.andThen(jsonNumberBigDecimal)
final lazy val jsonBigInt: Prism[Json, BigInt] = jsonNumber.andThen(jsonNumberBigInt)
final lazy val jsonLong: Prism[Json, Long] = jsonNumber.andThen(jsonNumberLong)
final lazy val jsonInt: Prism[Json, Int] = jsonNumber.andThen(jsonNumberInt)
final lazy val jsonShort: Prism[Json, Short] = jsonNumber.andThen(jsonNumberShort)
final lazy val jsonByte: Prism[Json, Byte] = jsonNumber.andThen(jsonNumberByte)
final lazy val jsonString: Prism[Json, String] = Prism[Json, String](_.asString)(Json.fromString)
final lazy val jsonNumber: Prism[Json, JsonNumber] = Prism[Json, JsonNumber](_.asNumber)(Json.fromJsonNumber)
final lazy val jsonObject: Prism[Json, JsonObject] = Prism[Json, JsonObject](_.asObject)(Json.fromJsonObject)
Expand All @@ -72,20 +72,20 @@ trait JsonOptics {

/** points to all values of a JsonObject or JsonList */
final lazy val jsonDescendants: Traversal[Json, Json] = new Traversal[Json, Json] {
override def modifyF[F[_]](f: Json => F[Json])(s: Json)(implicit F: Applicative[F]): F[Json] =
override def modifyA[F[_]](f: Json => F[Json])(s: Json)(implicit F: Applicative[F]): F[Json] =
s.fold(
F.pure(s),
_ => F.pure(s),
_ => F.pure(s),
_ => F.pure(s),
arr => F.map(Each.each[Vector[Json], Json].modifyF(f)(arr))(Json.arr(_: _*)),
obj => F.map(Each.each[JsonObject, Json].modifyF(f)(obj))(Json.fromJsonObject)
arr => F.map(Each.each[Vector[Json], Json].modifyA(f)(arr))(Json.arr(_: _*)),
obj => F.map(Each.each[JsonObject, Json].modifyA(f)(obj))(Json.fromJsonObject)
)
}

implicit final lazy val jsonPlated: Plated[Json] = new Plated[Json] {
val plate: Traversal[Json, Json] = new Traversal[Json, Json] {
def modifyF[F[_]](f: Json => F[Json])(a: Json)(implicit
def modifyA[F[_]](f: Json => F[Json])(a: Json)(implicit
F: Applicative[F]
): F[Json] =
a.fold(
Expand All @@ -100,4 +100,4 @@ trait JsonOptics {
}
}

final object JsonOptics extends JsonOptics
object JsonOptics extends JsonOptics
Loading

0 comments on commit 896a1e4

Please sign in to comment.