Skip to content

Commit 7ea50a2

Browse files
committed
compat layer for scala 2.12
1 parent eaf4051 commit 7ea50a2

File tree

20 files changed

+166
-73
lines changed

20 files changed

+166
-73
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
strategy:
2828
matrix:
2929
os: [ubuntu-latest]
30-
scala: [2.13.6, 3.0.0]
30+
scala: [2.12.13, 2.13.6, 3.0.0]
3131
java: [openjdk@1.11.0]
3232
runs-on: ${{ matrix.os }}
3333
steps:
@@ -101,6 +101,16 @@ jobs:
101101
~/Library/Caches/Coursier/v1
102102
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
103103

104+
- name: Download target directories (2.12.13)
105+
uses: actions/download-artifact@v2
106+
with:
107+
name: target-${{ matrix.os }}-2.12.13-${{ matrix.java }}
108+
109+
- name: Inflate target directories (2.12.13)
110+
run: |
111+
tar xf targets.tar
112+
rm targets.tar
113+
104114
- name: Download target directories (2.13.6)
105115
uses: actions/download-artifact@v2
106116
with:

build.sbt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ inThisBuild(
88
scalaVersion := ScalaVersions.v213,
99
description := "String diff for Scala",
1010
crossScalaVersions := Seq(
11+
ScalaVersions.v212,
1112
ScalaVersions.v213,
1213
ScalaVersions.v3
1314
),
@@ -22,7 +23,8 @@ inThisBuild(
2223
"PGP_SECRET" -> s"$${{ secrets.PGP_SECRET }}",
2324
"SONATYPE_PASSWORD" -> s"$${{ secrets.SONATYPE_PASSWORD }}",
2425
"SONATYPE_USERNAME" -> s"$${{ secrets.SONATYPE_USERNAME }}"
25-
))
26+
)),
27+
versionScheme := Some("early-semver")
2628
)
2729
)
2830

@@ -39,7 +41,8 @@ lazy val stringdiff =
3941
.settings(
4042
ScalaOptions.fixOptions,
4143
libraryDependencies ++= Seq(
42-
"org.scalatest" %%% "scalatest" % "3.2.9" % Test
44+
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.4.4",
45+
"org.scalatest" %%% "scalatest" % "3.2.9" % Test
4346
)
4447
)
4548

project/ScalaOptions.scala

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ object ScalaOptions {
1212
"-Wunused:params"
1313
)
1414
)),
15-
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
16-
case Some((2, _)) =>
17-
Seq(
18-
"-Ymacro-annotations"
19-
)
20-
case Some((3, _)) => Seq()
21-
case _ => Seq()
22-
}),
15+
scalacOptions ++= CrossVersion.partialVersion(scalaVersion.value).collect { case (2, 13) =>
16+
"-Ymacro-annotations"
17+
},
2318
(Compile / doc / scalacOptions) ~= (_.filterNot(
2419
Set(
2520
"-scalajs",

project/ScalaVersions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
object ScalaVersions {
2+
val v212 = "2.12.13"
23
val v213 = "2.13.6"
34
val v3 = "3.0.0"
45
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package app.tulz.diff
2+
package compat
3+
4+
import scala.collection.SeqView
5+
import scala.collection.immutable.Range
6+
7+
class IndexedSeqView[A](
8+
private[compat] val underlying: SeqView[A, _]
9+
) {
10+
def apply(index: Int): A = underlying(index)
11+
12+
def size: Int = underlying.length
13+
14+
def isEmpty: Boolean = underlying.isEmpty
15+
16+
def concat(other: IndexedSeqView[A]): IndexedSeqView[A] =
17+
new IndexedSeqView((underlying ++ other.underlying).view)
18+
19+
def take(n: Int): IndexedSeqView[A] = new IndexedSeqView(underlying.take(n))
20+
21+
def slice(from: Int, until: Int): IndexedSeqView[A] = new IndexedSeqView(underlying.slice(from, until))
22+
23+
def toIndexedSeq: IndexedSeq[A] = underlying.toIndexedSeq
24+
25+
def indices: Range = underlying.indices
26+
27+
def forall(predicate: A => Boolean): Boolean = underlying.forall(predicate)
28+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package app.tulz.diff.compat
2+
3+
class IndexedSeqViewOfCharOps(
4+
underlying: IndexedSeqView[Char]
5+
) {
6+
7+
def mkString: String = underlying.underlying.mkString
8+
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package app.tulz.diff.compat
2+
3+
class IndexedSeqViewOfStringOps(
4+
underlying: IndexedSeqView[String]
5+
) {
6+
7+
def mkString: String = underlying.underlying.mkString
8+
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package app.tulz.diff
2+
3+
import scala.collection.SeqView
4+
import scala.language.implicitConversions
5+
6+
package object compat {
7+
8+
implicit def indexedSeq_ViewToIndexedSeqView[A](
9+
underlying: SeqView[A, IndexedSeq[A]]
10+
): IndexedSeqView[A] = new IndexedSeqView[A](underlying)
11+
12+
implicit def string_ViewToIndexedSeqView(
13+
underlying: SeqView[Char, String]
14+
): IndexedSeqView[Char] = new IndexedSeqView[Char](underlying)
15+
16+
implicit def indexedSeqViewOfCharOps(
17+
underlying: IndexedSeqView[Char]
18+
): IndexedSeqViewOfCharOps = new IndexedSeqViewOfCharOps(underlying)
19+
20+
implicit def indexedSeqViewOfStringOps(
21+
underlying: IndexedSeqView[String]
22+
): IndexedSeqViewOfStringOps = new IndexedSeqViewOfStringOps(underlying)
23+
24+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package app.tulz.diff
2+
3+
package object compat {
4+
5+
type IndexedSeqView[+A] = scala.collection.IndexedSeqView[A]
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package app.tulz.diff
2+
3+
package object compat {
4+
5+
type IndexedSeqView[+A] = scala.collection.IndexedSeqView[A]
6+
7+
}

0 commit comments

Comments
 (0)