• Stars
    star
    200
  • Rank 188,230 (Top 4 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated 24 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

makes some Scala 2.13 APIs (primarily collections, also some others) available on 2.11 and 2.12, to aid cross-building

scala-collection-compat Scala version support

Purpose and scope

This library makes some Scala 2.13 APIs available on Scala 2.11 and 2.12.

The idea is to facilitate cross-building Scala 2.13 and 3.0 code on the older versions.

Although the name of the library is scala-"collection"-compat, we have now widened the scope to include other parts of the Scala 2.13/3.0 standard library besides just collections.

Only the most commonly used APIs are supported; many are missing. Contributions are welcome.

Usage

To use this library, add the following to your build.sbt:

libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "<version>"

All future versions will remain backwards binary compatible with 2.0.0. (The 1.0.0 release was withdrawn and should not be used.)

How it works

The 2.13 and 3.0 versions consist only of an empty scala.collection.compat package object, so import scala.collection.compat._ won't cause an error in cross-compiled code.

The 2.11 and 2.12 versions have the needed compatibility code in this package.

Changed methods

The 2.13 collections redesign did not break source compatibility for most ordinary code, but there are some exceptions.

For example, the to method is used with a type parameter in 2.12:

xs.to[List]

With this compatibility library you can instead use the 2.13 syntax, which takes a value parameter:

import scala.collection.compat._
xs.to(List)

New collections

The library also adds backported versions of new collection types, such as immutable.ArraySeq and immutable.LazyList. (On 2.13, these types are just aliases to standard library types.)

New collection methods

Support is included for some 2.13 collections methods such as maxOption.

Other new classes

Support is included for some non-collections classes, such as:

  • @nowarn annotation, added in 2.13.2 and 2.12.13. (The 2.11 @nowarn doesn't do anything, but its presence facilitates cross-compilation.)

Other new methods

Support is included for some other methods, such as:

  • toIntOption (and Long, et al) on String

Migration rules

The migration rules use scalafix. Please see the official installation instructions if you are using an old version of sbt (<1.3) or in case the commands below do not work.

// project/plugins.sbt
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1")

Collection213Upgrade

The Collection213Upgrade rewrite upgrades to the 2.13 collections without the ability to compile the code-base with 2.12 or 2.11. This rewrite is suitable for applications that don't need to cross-compile against multiple Scala versions.

// build.sbt
scalacOptions += "-P:semanticdb:synthetics:on"
// sbt shell
> scalafixEnable
> scalafixAll dependency:[email protected]:scala-collection-migrations:<version>

Collection213CrossCompat

The Collection213CrossCompat rewrite upgrades to the 2.13 collections with the ability to compile the code-base with 2.12 or later. This rewrite is suitable for libraries that are cross-published for multiple Scala versions.

To cross-build for 2.12 and 2.11, the rewrite rule introduces a dependency on the scala-collection-compat module, which provides some APIs of 2.13 on 2.12 and 2.11. This enables you to write your library using the latest 2.13 collections API while still supporting users on an older Scala version.

// build.sbt
libraryDependencies +=  "org.scala-lang.modules" %% "scala-collection-compat" % "<version>"
scalacOptions += "-P:semanticdb:synthetics:on"
// sbt shell
> scalafixEnable
> scalafixAll dependency:[email protected]:scala-collection-migrations:<version>

Fixing unused import warnings

In Scala 2.13 the import scala.collection.compat._ sometimes is not needed (e.g. .to(SeqType) is natively available). This leads to a unused import warning under Scala 2.13 even though the import is required for Scala 2.12. In order to work around this, you can pass a compiler option to ignore this specific issue, e.g. in SBT:

scalacOptions += "-Wconf:origin=scala.collection.compat.*:s"

Contributing

The migration tool is not exhaustive. Contributions of additional rewrites are welcome. If you encounter a use case that’s not supported, please report it as described in the contributing documentation.

More Repositories

1

scala

Scala 2 compiler and standard library. Bugs at https://github.com/scala/bug; Scala 3 at https://github.com/scala/scala3
Scala
14,269
star
2

scala3

The Scala 3 compiler, also known as Dotty.
Scala
5,669
star
3

scala-async

An asynchronous programming facility for Scala
Scala
1,138
star
4

pickling

Fast, customizable, boilerplate-free pickling support for Scala
Scala
833
star
5

scala-parser-combinators

simple combinator-based parsing for Scala. formerly part of the Scala standard library, now a separate community-maintained module
Scala
642
star
6

docs.scala-lang

The Scala Documentation website
HTML
551
star
7

scala-java8-compat

A Java 8 (and up) compatibility kit for Scala.
Scala
436
star
8

legacy-svn-scala

OBSOLETE, we're over there:
Scala
366
star
9

scala3-example-project

An example sbt project that compiles using Dotty
Scala
332
star
10

scala-xml

The standard Scala XML library
Scala
292
star
11

scala-dist

sbt project that packages the Scala distribution
Scala
276
star
12

scala-lang

sources for the Scala language website
SCSS
259
star
13

scala-abide

obsolete; visit https://github.com/scalacenter/scalafix instead
Scala
232
star
14

bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
230
star
15

collection-strawman

Implementation of the new Scala 2.13 Collections
Scala
201
star
16

scala-parallel-collections

Parallel collections standard library module for Scala 2.13+
Scala
194
star
17

scala-seed.g8

Giter8 template for a simple hello world app in Scala.
Scala
146
star
18

scala-dev

Scala 2 team issues. Not for user-facing bugs or directly actionable user-facing improvements. For build/test/infra and for longer-term planning and idea tracking. Our bug tracker is at https://github.com/scala/bug/issues
132
star
19

community-build

Scala 2 community build — a corpus of open-source repos built against Scala nightlies
Shell
129
star
20

scala-swing

Scala wrappers for Java's Swing API for desktop GUIs
Scala
126
star
21

scala3.g8

Scala
123
star
22

scala-collection-contrib

community-contributed additions to the Scala 2.13 collections
Scala
106
star
23

scala-module-dependency-sample

Depend on Scala modules like a pro
Scala
95
star
24

scala-continuations

the Scala delimited continuations plugin and library
Scala
89
star
25

make-release-notes

The project that generates Scala release notes.
HTML
85
star
26

toolkit

The batteries-included Scala
Scala
81
star
27

vscode-scala-syntax

Visual Studio Code extension for syntax highlighting Scala sources
Scala
72
star
28

compiler-benchmark

Benchmarks for scalac
Scala
68
star
29

slip

obsolete — archival use only
68
star
30

scala-library-next

backwards-binary-compatible Scala standard library additions
Scala
66
star
31

improvement-proposals

Scala Improvement Proposals
42
star
32

scala.epfl.ch

web site for the Scala Center @ EPFL in Switzerland
SCSS
37
star
33

scala-tool-support

XML
34
star
34

hello-world.g8

Scala
27
star
35

scala-collection-laws

partially-automatic generation of tests for the entire collections library
Scala
21
star
36

scala3-cross.g8

Scala
17
star
37

scabot

Scala's PR&CI automation bot
Scala
14
star
38

sbt-scala-module

sbt plugin for scala modules.
Scala
14
star
39

scala-jenkins-infra

A Chef cookbook that manages Scala's CI infrastructure.
Shell
14
star
40

scalatest-example.g8

Scala
13
star
41

scala3-mill-example-project

Shell
12
star
42

scala-asm

A fork of https://gitlab.ow2.org/asm/asm for the Scala compiler
12
star
43

compiler-interface

a binary contract between Zinc and Scala Compilers
Scala
10
star
44

scala-partest

Legacy repo for testing framework for Scala versions <= 2.12
Scala
9
star
45

scala-asm-legacy

A fork of asm.ow2.org for the Scala compiler
Java
8
star
46

scala3-staging.g8

Scala
7
star
47

scala-modules-build

Build support for the various Scala Modules
Shell
1
star
48

actors-migration

Scala
1
star
49

scala-partest-interface

SBT interface to partest
1
star
50

scala-library-all

Conglomerate pom file to pull in components of Scala standard library easily.
Scala
1
star
51

scala-dist-smoketest

Smoke Test for newly created Scala distributions
Shell
1
star
52

scala3-tasty-inspector.g8

Scala
1
star