A compatibility library that makes Scala 2.13 APIs available on Scala 2.11 and 2.12, facilitating cross-building and migration to newer Scala versions.
npx @tessl/cli install tessl/maven-org-scala-lang-modules--scala-collection-compat_2-12@2.13.0Scala Collection Compat is a compatibility library that makes Scala 2.13 APIs available on Scala 2.11 and 2.12, facilitating cross-building and migration to newer Scala versions. It provides backported collection types, enhanced collection methods, Java interoperability utilities, and resource management features.
libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "2.13.0"import scala.collection.compat._This single import provides access to all compatibility features including:
import scala.collection.compat._
// Use 2.13-style collection operations on 2.11/2.12
val numbers = List(1, 2, 3, 4, 5)
numbers.to(Vector) // Instead of numbers.to[Vector]
// Safe string parsing
val maybeInt: Option[Int] = "42".toIntOption
val maybeDouble: Option[Double] = "3.14".toDoubleOption
// Enhanced collection methods
val data = List(1, 2, 3, 4, 5)
val min = data.minOption // Safe minimum without exceptions
val max = data.maxOption // Safe maximum without exceptions
// Size comparison operations
if (data.sizeIs > 3) println("Large collection")
// Backported lazy list
val infinite = LazyList.from(1)
val first10 = infinite.take(10).toListScala Collection Compat is organized around several key components:
Enhanced methods for existing Scala collections including safe operations, size comparisons, and functional utilities. Provides 2.13-style APIs on older Scala versions.
// Extension methods available through import scala.collection.compat._
def minOption[B >: A](implicit ord: Ordering[B]): Option[A]
def maxOption[B >: A](implicit ord: Ordering[B]): Option[A]
def sizeCompare(otherSize: Int): Int
def sizeIs: SizeCompareOps
def distinctBy[B](f: A => B): Collection[A]
def groupMap[K, B](key: A => K)(f: A => B): Map[K, Collection[B]]Complete implementations of Scala 2.13 collection types for use on Scala 2.11 and 2.12, including ArraySeq and LazyList with full feature parity.
object ArraySeq {
def apply[T](elems: T*)(implicit elemTag: ClassTag[T]): ArraySeq[T]
def from[T](source: TraversableOnce[T])(implicit elemTag: ClassTag[T]): ArraySeq[T]
def unsafeWrapArray[T](x: Array[T]): ArraySeq[T]
}
object LazyList {
def apply[A](elems: A*): LazyList[A]
def from[A](coll: GenTraversableOnce[A]): LazyList[A]
def iterate[A](start: => A)(f: A => A): LazyList[A]
def continually[A](elem: => A): LazyList[A]
}Safe string parsing methods that return Option types instead of throwing exceptions, providing consistent parsing across all numeric types.
implicit class StringOps(s: String) {
def toBooleanOption: Option[Boolean]
def toByteOption: Option[Byte]
def toShortOption: Option[Short]
def toIntOption: Option[Int]
def toLongOption: Option[Long]
def toFloatOption: Option[Float]
def toDoubleOption: Option[Double]
}Utilities for converting between Scala and Java collections with both implicit and explicit conversion methods.
import scala.jdk.CollectionConverters._
// Implicit conversions available through .asScala/.asJava extension methods
import scala.jdk.javaapi.CollectionConverters
// Explicit conversion methods for Java interop
def asScala[A](c: ju.Collection[A]): Iterable[A]
def asJava[A](i: Iterable[A]): jl.Iterable[A]Automatic resource management with try-with-resources semantics through the Using utility, supporting single and multiple resource management.
object Using {
def apply[R: Releasable, A](resource: => R)(f: R => A): Try[A]
def resource[R, A](resource: R)(body: R => A)(implicit releasable: Releasable[R]): A
def resources[R1: Releasable, R2: Releasable, A](r1: R1, r2: => R2)(body: (R1, R2) => A): A
}
trait Releasable[-R] {
def release(resource: R): Unit
}Additional utilities including chaining operations, annotations for cross-compilation, and enhanced regex functionality.
final class ChainingOps[A](self: A) {
def tap[U](f: A => U): A
def pipe[B](f: A => B): B
}
class nowarn(value: String = "")
final class unused
implicit class RegexOps(regex: Regex) {
def matches(source: CharSequence): Boolean
}type IterableOnce[+X] = scala.collection.TraversableOnce[X] // 2.11/2.12
type Factory[-A, +C] = CanBuildFrom[Nothing, A, C] // 2.11/2.12
type BuildFrom[-From, -A, +C] = /* implementation */ // 2.11/2.12
// On Scala 2.13, these are aliases to standard library types
type Factory[-A, +C] = scala.collection.Factory[A, C] // 2.13
type BuildFrom[-From, -A, +C] = scala.collection.BuildFrom[From, A, C] // 2.13trait BuildFrom[-From, -A, +C] {
def fromSpecific(from: From)(it: IterableOnce[A]): C
def newBuilder(from: From): mutable.Builder[A, C]
}
trait Factory[-A, +C] {
def fromSpecific(it: IterableOnce[A]): C
def newBuilder: mutable.Builder[A, C]
}