Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: scala/scala-collection-compat
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.10.0
Choose a base ref
...
head repository: scala/scala-collection-compat
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.11.0
Choose a head ref
  • 8 commits
  • 7 files changed
  • 6 contributors

Commits on Apr 26, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    644445f View commit details

Commits on May 25, 2023

  1. Update sbt to 1.8.3

    scala-steward committed May 25, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    scala-steward Scala Steward
    Copy the full SHA
    09e146d View commit details
  2. Merge pull request #594 from scala-steward/update/sbt-1.8.3

    Update sbt to 1.8.3
    xuwei-k authored May 25, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4a29462 View commit details

Commits on May 28, 2023

  1. Add RegexOps

    jozic committed May 28, 2023
    Copy the full SHA
    956249b View commit details

Commits on Jun 3, 2023

  1. Update sbt to 1.9.0

    scala-steward authored and xuwei-k committed Jun 3, 2023
    Copy the full SHA
    a791e2d View commit details

Commits on Jun 10, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    41e99c7 View commit details

Commits on Jun 14, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c0ec12b View commit details

Commits on Jun 15, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    04db1f4 View commit details
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -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(
Original file line number Diff line number Diff line change
@@ -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](
Original file line number Diff line number Diff line change
@@ -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()
}

}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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"))
}

}
Original file line number Diff line number Diff line change
@@ -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)
}
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.8.2
sbt.version=1.9.0