From a6e8629027b89907dcdcdd941f52882f78aa1c5e Mon Sep 17 00:00:00 2001 From: Jack Viers Date: Sat, 9 Nov 2019 12:52:01 -0600 Subject: [PATCH] Backports #3133 to scala_2.11 * Adds scala version specific src directories * Backports PR #3133 to add scala 2.11 support * Brings scalafmt plugin and configs utd with master --- .scalafmt.conf | 2 +- .../cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala | 6 ++++++ .../cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala | 6 ++++++ .../cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala | 3 +++ core/src/main/scala/cats/data/NonEmptyChain.scala | 6 ++---- tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 core/src/main/scala-2.11/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala create mode 100644 core/src/main/scala-2.12/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala create mode 100644 core/src/main/scala-2.13+/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala diff --git a/.scalafmt.conf b/.scalafmt.conf index 5fd2f83ac5..c39b553a74 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -6,4 +6,4 @@ continuationIndent.defnSite = 2 assumeStandardLibraryStripMargin = true danglingParentheses = true rewrite.rules = [AvoidInfix, SortImports, RedundantBraces, RedundantParens, SortModifiers] -docstrings = JavaDoc +docstrings = JavaDoc \ No newline at end of file diff --git a/core/src/main/scala-2.11/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala b/core/src/main/scala-2.11/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala new file mode 100644 index 0000000000..35ca7ff5cf --- /dev/null +++ b/core/src/main/scala-2.11/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala @@ -0,0 +1,6 @@ +package cats.data + +private[data] trait ScalaVersionSpecificNonEmptyChainImpl { + def fromSeq[A](as: scala.collection.Seq[A]): Option[NonEmptyChain[A]] = + if (as.nonEmpty) Option(NonEmptyChainImpl.create(Chain.fromSeq(as))) else None +} diff --git a/core/src/main/scala-2.12/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala b/core/src/main/scala-2.12/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala new file mode 100644 index 0000000000..35ca7ff5cf --- /dev/null +++ b/core/src/main/scala-2.12/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala @@ -0,0 +1,6 @@ +package cats.data + +private[data] trait ScalaVersionSpecificNonEmptyChainImpl { + def fromSeq[A](as: scala.collection.Seq[A]): Option[NonEmptyChain[A]] = + if (as.nonEmpty) Option(NonEmptyChainImpl.create(Chain.fromSeq(as))) else None +} diff --git a/core/src/main/scala-2.13+/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala b/core/src/main/scala-2.13+/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala new file mode 100644 index 0000000000..5005b53f9c --- /dev/null +++ b/core/src/main/scala-2.13+/cats/data/ScalaVersionSpecificNonEmptyChainImpl.scala @@ -0,0 +1,3 @@ +package cats.data + +private[data] trait ScalaVersionSpecificNonEmptyChainImpl diff --git a/core/src/main/scala/cats/data/NonEmptyChain.scala b/core/src/main/scala/cats/data/NonEmptyChain.scala index fc4ed37435..667d0d793c 100644 --- a/core/src/main/scala/cats/data/NonEmptyChain.scala +++ b/core/src/main/scala/cats/data/NonEmptyChain.scala @@ -21,9 +21,7 @@ import NonEmptyChainImpl.create import cats.{Order, Semigroup} import cats.kernel._ -import scala.collection.immutable._ - -private[data] object NonEmptyChainImpl extends NonEmptyChainInstances { +private[data] object NonEmptyChainImpl extends NonEmptyChainInstances with ScalaVersionSpecificNonEmptyChainImpl { // The following 3 types are components of a technique to // create a no-boxing newtype. It's coped from the // newtypes lib by @alexknvl @@ -52,7 +50,7 @@ private[data] object NonEmptyChainImpl extends NonEmptyChainInstances { def fromNonEmptyVector[A](as: NonEmptyVector[A]): NonEmptyChain[A] = create(Chain.fromSeq(as.toVector)) - def fromSeq[A](as: Seq[A]): Option[NonEmptyChain[A]] = + def fromSeq[A](as: scala.collection.immutable.Seq[A]): Option[NonEmptyChain[A]] = if (as.nonEmpty) Option(create(Chain.fromSeq(as))) else None def fromChainPrepend[A](a: A, ca: Chain[A]): NonEmptyChain[A] = diff --git a/tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala b/tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala index 2d76aa261b..478f3cc701 100644 --- a/tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala +++ b/tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala @@ -106,7 +106,7 @@ class NonEmptyChainSuite extends CatsSuite { test("fromSeq . toList . iterator is id") { forAll { (ci: NonEmptyChain[Int]) => - NonEmptyChain.fromSeq(ci.iterator.toList) should ===(Option(ci)) + NonEmptyChain.fromSeq(ci.iterator.toSeq) should ===(Option(ci)) } }