Giter Club home page Giter Club logo

scala-collection-compat's Introduction

Build Status

Scala 2.13 Collection Compatibility Library And Migration Tool

Compatibility Library

This library provides some of the new APIs from Scala 2.13 to Scala 2.11 and 2.12. It can be used to cross-build projects. To use this library, add the following to your build.sbt:

libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "2.1.3"

Version 2.0.0+ is compatible with Scala 2.13, 2.12, and 2.11.

Note that there are multiple ways to cross-build projects, see https://github.com/scala/collection-strawman/wiki/FAQ#how-do-i-cross-build-my-project-against-scala-212-and-scala-213.

Note: Please do not release any artifacts against version 1.0.0, due to #195.

Backwards binary compatibility will be enforced within each major version (i.e. all 1.x.y releases will be binary compatible).

The 2.13 collections are mostly backwards source-compatible, 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 also use the 2.13 syntax which uses a companion object:

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

The 2.13 version consists only of an empty scala.collection.compat package object that allows you to write import scala.collection.compat._ in 2.13. The 2.11/2.12 version has the compatibility extensions in this package.

The library also adds backported versions of new collection types, currently scala.collection.compat.immutable.ArraySeq. In 2.11/2.12, this type is a new collection implementation. In 2.13, it is an alias for scala.collection.immutable.ArraySeq.

Migration Tool

The migration rules use scalafix. Please see the official installation instruction and, in particular, check that your full Scala version is supported (ex 2.12.10).

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

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
scalafixDependencies in ThisBuild += "org.scala-lang.modules" %% "scala-collection-migrations" % "2.1.3"
addCompilerPlugin(scalafixSemanticdb)
scalacOptions ++= List("-Yrangepos", "-P:semanticdb:synthetics:on")
// sbt shell
> ;test:scalafix Collection213Upgrade ;scalafix Collection213Upgrade

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 the syntax 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
scalafixDependencies in ThisBuild += "org.scala-lang.modules" %% "scala-collection-migrations" % "2.1.3"
libraryDependencies +=  "org.scala-lang.modules" %% "scala-collection-compat" % "2.1.3"
addCompilerPlugin(scalafixSemanticdb)
scalacOptions ++= List("-Yrangepos", "-P:semanticdb:synthetics:on")
// sbt shell
> ;test:scalafix Collection213CrossCompat ;scalafix Collection213CrossCompat

Build.scala

// If you are using project/Build.scala add the following imports:
import scalafix.sbt.ScalafixPlugin.autoImport.{scalafixDependencies, scalafixSemanticdb}

Contributing

The migration tool is not exhaustive and we will continue to improve it over time. If you encounter a use case that’s not supported, please report it as described in the contributing documentation.

scala-collection-compat's People

Contributors

julienrf avatar masseguillaume avatar sethtisue avatar lrytz avatar scala-steward avatar olafurpg avatar szeiger avatar dwijnand avatar ekrich avatar xerial avatar xuwei-k avatar eed3si9n avatar marcelocenerine avatar smarter avatar raboof avatar maximekjaer avatar pjfanning avatar sjrd avatar lavrov avatar wsargent avatar yufangong avatar ghik avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.