Skip to content

Commit 93b6fc9

Browse files
committed
add sources
1 parent 09eaf93 commit 93b6fc9

File tree

8 files changed

+74
-1
lines changed

8 files changed

+74
-1
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @xuwei-k

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: ci
2+
on:
3+
pull_request:
4+
push:
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
steps:
11+
- uses: actions/[email protected]
12+
- uses: actions/setup-java@v2
13+
with:
14+
java-version: 8
15+
check-latest: true
16+
distribution: adopt
17+
- uses: coursier/cache-action@v6
18+
- run: curl -Ls https://git.io/sbt > ./sbt && chmod 0755 ./sbt
19+
- run: ./sbt -v "+ Test/run"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# case-class-to-tuple-cross-build
21
example repository for `toTuple` method
2+
3+
https://github.com/lampepfl/dotty/issues/2335

build.sbt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def Scala213 = "2.13.6"
2+
def Scala3 = "3.0.0"
3+
4+
scalaVersion := Scala213
5+
6+
crossScalaVersions := Seq(Scala213, Scala3)
7+
8+
libraryDependencies ++= {
9+
if (CrossVersion.partialVersion(scalaVersion.value).exists(_._1 == 2)) {
10+
Seq("com.chuusai" %% "shapeless" % "2.3.7")
11+
} else {
12+
Nil
13+
}
14+
}

project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.5.2

src/main/scala-2/AsTuple.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import shapeless.ops.product.ToTuple
2+
3+
object AsTuple {
4+
implicit class AsTupleOps[A](private val value: A) extends AnyVal {
5+
def asTuple[B](implicit toTuple: ToTuple.Aux[A, B]): B =
6+
toTuple.apply(value)
7+
}
8+
}

src/main/scala-3/AsTuple.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.deriving.Mirror.ProductOf
2+
3+
object AsTuple {
4+
extension [A <: Product](value: A) {
5+
def asTuple(using mirror: ProductOf[A]): mirror.MirroredElemTypes =
6+
Tuple.fromProductTyped(value)
7+
}
8+
}

src/test/scala/TestMain.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import AsTuple._
2+
3+
object TestMain {
4+
5+
case class A(x1: Int, x2: String)
6+
7+
case class B[T](x1: T, x2: List[T], x3: Option[T])
8+
9+
def a = A(2, "a").asTuple
10+
11+
def b = B[Boolean](false, List(true, false), Option(true)).asTuple
12+
13+
def main(args: Array[String]): Unit = {
14+
a: (Int, String)
15+
b: (Boolean, List[Boolean], Option[Boolean])
16+
17+
println(a)
18+
println(b)
19+
}
20+
21+
}

0 commit comments

Comments
 (0)