From 644445f0b3430cd5bafef4533c36adeab4e10532 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Wed, 26 Apr 2023 16:57:51 -0700 Subject: [PATCH 1/6] reset version policy, post-2.10.0 (#593) --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 94358e35..74dd2995 100644 --- a/build.sbt +++ b/build.sbt @@ -82,7 +82,7 @@ lazy val compat = new MultiScalaCrossProject( sharedSourceDir / "scala-2.11_2.12" } }, - versionPolicyIntention := Compatibility.BinaryCompatible, + versionPolicyIntention := Compatibility.BinaryAndSourceCompatible, mimaBinaryIssueFilters ++= { import com.typesafe.tools.mima.core._ import com.typesafe.tools.mima.core.ProblemFilters._ From 09e146dc2eaf81ffef92516ab8b2bff954d3518f Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Thu, 25 May 2023 08:49:42 +0000 Subject: [PATCH 2/6] Update sbt to 1.8.3 --- project/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/build.properties b/project/build.properties index 46e43a97..72413de1 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.8.2 +sbt.version=1.8.3 From 956249b46bdb593d40824c96d700e597e34ab1db Mon Sep 17 00:00:00 2001 From: Eugene Platonov Date: Sat, 27 May 2023 23:34:05 -0400 Subject: [PATCH 3/6] Add `RegexOps` --- build.sbt | 2 +- .../scala/util/matching/compat/package.scala | 30 +++++++++++++++++++ .../scala/util/matching/compat/package.scala | 18 +++++++++++ .../util/matching/compat/RegexOpsTest.scala | 26 ++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 compat/src/main/scala-2.11_2.12/scala/util/matching/compat/package.scala create mode 100644 compat/src/main/scala-2.13/scala/util/matching/compat/package.scala create mode 100644 compat/src/test/scala/scala/util/matching/compat/RegexOpsTest.scala diff --git a/build.sbt b/build.sbt index 74dd2995..94358e35 100644 --- a/build.sbt +++ b/build.sbt @@ -82,7 +82,7 @@ lazy val compat = new MultiScalaCrossProject( sharedSourceDir / "scala-2.11_2.12" } }, - versionPolicyIntention := Compatibility.BinaryAndSourceCompatible, + versionPolicyIntention := Compatibility.BinaryCompatible, mimaBinaryIssueFilters ++= { import com.typesafe.tools.mima.core._ import com.typesafe.tools.mima.core.ProblemFilters._ diff --git a/compat/src/main/scala-2.11_2.12/scala/util/matching/compat/package.scala b/compat/src/main/scala-2.11_2.12/scala/util/matching/compat/package.scala new file mode 100644 index 00000000..9f0bf8f2 --- /dev/null +++ b/compat/src/main/scala-2.11_2.12/scala/util/matching/compat/package.scala @@ -0,0 +1,30 @@ +/* + * Scala (https://www.scala-lang.org) + * + * Copyright EPFL and Lightbend, Inc. + * + * Licensed under Apache License 2.0 + * (http://www.apache.org/licenses/LICENSE-2.0). + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ + +package scala.util.matching + +package object compat { + final implicit class RegexOps(val regex: Regex) extends AnyVal { + + /** Returns whether this `Regex` matches the given character sequence. + * + * Like the extractor, this method takes anchoring into account. + * + * @param source The text to match against + * @return true if and only if `source` matches this `Regex`. + * @see [[Regex#unanchored]] + * @example {{{"""\d+""".r matches "123" // returns true}}} + */ + def matches(source: CharSequence): Boolean = regex.pattern.matcher(source).matches() + } + +} diff --git a/compat/src/main/scala-2.13/scala/util/matching/compat/package.scala b/compat/src/main/scala-2.13/scala/util/matching/compat/package.scala new file mode 100644 index 00000000..7d0454c5 --- /dev/null +++ b/compat/src/main/scala-2.13/scala/util/matching/compat/package.scala @@ -0,0 +1,18 @@ +/* + * Scala (https://www.scala-lang.org) + * + * Copyright EPFL and Lightbend, Inc. + * + * Licensed under Apache License 2.0 + * (http://www.apache.org/licenses/LICENSE-2.0). + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ + +package scala.util.matching + +package object compat { + type Regex = scala.util.matching.Regex + val Regex = scala.util.matching.Regex +} diff --git a/compat/src/test/scala/scala/util/matching/compat/RegexOpsTest.scala b/compat/src/test/scala/scala/util/matching/compat/RegexOpsTest.scala new file mode 100644 index 00000000..212c2699 --- /dev/null +++ b/compat/src/test/scala/scala/util/matching/compat/RegexOpsTest.scala @@ -0,0 +1,26 @@ +/* + * Scala (https://www.scala-lang.org) + * + * Copyright EPFL and Lightbend, Inc. + * + * Licensed under Apache License 2.0 + * (http://www.apache.org/licenses/LICENSE-2.0). + * + * See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + */ + +package scala.util.matching.compat + +import org.junit.Assert._ +import org.junit.Test + +class RegexOpsTest { + + @Test + def testMatches(): Unit = { + assertTrue(".*hello.*".r.matches("hey hello")) + assertFalse(".*hello.*".r.matches("hey hop")) + } + +} From a791e2de02b8d94b42c075117dc590bbfaa456d1 Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Sat, 3 Jun 2023 03:33:47 +0000 Subject: [PATCH 4/6] Update sbt to 1.9.0 --- project/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/build.properties b/project/build.properties index 72413de1..40b3b8e7 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.8.3 +sbt.version=1.9.0 From c0ec12bddd003384fb9fee075f96aa4414f0f28b Mon Sep 17 00:00:00 2001 From: Scala Steward <43047562+scala-steward@users.noreply.github.com> Date: Wed, 14 Jun 2023 05:18:32 +0200 Subject: [PATCH 5/6] Update scala-library to 2.13.11 (#601) --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 94358e35..7e466950 100644 --- a/build.sbt +++ b/build.sbt @@ -52,7 +52,7 @@ lazy val junit = libraryDependencies += "com.github.sbt" % "junit-interface" % " lazy val scala211 = "2.11.12" lazy val scala212 = "2.12.17" -lazy val scala213 = "2.13.10" +lazy val scala213 = "2.13.11" lazy val scala3 = "3.2.2" lazy val compat = new MultiScalaCrossProject( From 04db1f4234a64407fed497eaec978e4657c34104 Mon Sep 17 00:00:00 2001 From: Alex Klibisz Date: Thu, 15 Jun 2023 09:40:51 -0400 Subject: [PATCH 6/6] Add implementation of distinctBy (#602) --- .../scala/collection/compat/PackageShared.scala | 13 +++++++++++++ .../test/scala/collection/CollectionTest.scala | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala b/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala index 4bd70b48..8e12de82 100644 --- a/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala +++ b/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala @@ -564,6 +564,19 @@ class TraversableLikeExtensionMethods[A, Repr](private val self: c.GenTraversabl } map.toMap } + + def distinctBy[B, That](f: A => B)(implicit cbf: CanBuildFrom[Repr, A, That]): That = { + val builder = cbf() + val keys = collection.mutable.Set.empty[B] + for (element <- self) { + val key = f(element) + if (!keys.contains(key)) { + builder += element + keys += key + } + } + builder.result() + } } class TrulyTraversableLikeExtensionMethods[El1, Repr1]( diff --git a/compat/src/test/scala/test/scala/collection/CollectionTest.scala b/compat/src/test/scala/test/scala/collection/CollectionTest.scala index 733c070b..4136a10b 100644 --- a/compat/src/test/scala/test/scala/collection/CollectionTest.scala +++ b/compat/src/test/scala/test/scala/collection/CollectionTest.scala @@ -186,4 +186,11 @@ class CollectionTest { assertTrue(List(1, 2, 3).lengthIs >= 2) assertTrue(List(1, 2, 3).lengthIs > 2) } + + @Test + def testDistinctBy(): Unit = { + assertEquals(List(1, 2, 3).distinctBy(_ % 2 == 0), List(1, 2)) + assertEquals(List(3, 1, 2).distinctBy(_ % 2 == 0), List(3, 2)) + assertEquals(List.empty[Int].distinctBy(_ % 2 == 0), List.empty) + } }