Skip to content

Commit

Permalink
Setup case class derivation compatibility sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Apr 15, 2023
1 parent 7a276bb commit 0ab5302
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.bsp
.metals
.vscode
target/
2 changes: 2 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "3.6.1"
runner.dialect = scala213
8 changes: 8 additions & 0 deletions app/src/main/scala/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import cats.syntax.all._
import PersonSemigroup._

object App {
def main(args: Array[String]): Unit = {
println(Person("foo", 2) |+| Person("bar", 3))
}
}
21 changes: 21 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ThisBuild / scalaVersion := "3.2.2"
ThisBuild / crossScalaVersions := Seq("2.13.10", "3.2.2")

lazy val personOld = project
lazy val personNew = project.settings(
mimaPreviousClassfiles := Map(
projectID.value -> (personOld / Compile / classDirectory).value
),
mimaReportBinaryIssues :=
mimaReportBinaryIssues
.dependsOn(personOld / Compile / compile)
.value
)

lazy val lib = project
.settings(
libraryDependencies += "org.typelevel" %% "kittens" % "3.0.0"
)
.dependsOn(personOld % Provided)

val app = project.dependsOn(lib, personNew)
6 changes: 6 additions & 0 deletions lib/src/main/scala/PersonSemigroup.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import cats._
import cats.derived._

object PersonSemigroup {
implicit def instance: Semigroup[Person] = semiauto.semigroup
}
17 changes: 17 additions & 0 deletions personNew/src/main/scala/Person.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
case class Person private (name: String, age: Int) {
def this(name: String) = this(name, -1)

def withName(name: String): Person = copy(name = name)
def withAge(age: Int): Person = copy(age = age)

private def copy(name: String = this.name, age: Int = this.age): Person =
new Person(name, age)
}

object Person {
def apply(name: String, age: Int): Person = new Person(name, age)

def apply(name: String): Person = new Person(name)

private def unapply(person: Person): Some[Person] = Some(person)
}
11 changes: 11 additions & 0 deletions personOld/src/main/scala/Person.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
case class Person private (name: String) {
def withName(name: String): Person = copy(name = name)

private def copy(name: String = this.name): Person =
new Person(name)
}

object Person {
def apply(name: String): Person = new Person(name)
private def unapply(person: Person): Some[Person] = Some(person)
}
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.8.2
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.2")

0 comments on commit 0ab5302

Please sign in to comment.