Skip to content

Commit

Permalink
Backports typelevel#3133 to scala_2.11
Browse files Browse the repository at this point in the history
* Adds scala version specific src directories
* Backports PR typelevel#3133 to add scala 2.11 support
* Brings scalafmt plugin and configs utd with master
  • Loading branch information
jackcviers committed Nov 13, 2019
1 parent 14b8557 commit a6e8629
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
danglingParentheses = true
rewrite.rules = [AvoidInfix, SortImports, RedundantBraces, RedundantParens, SortModifiers]
docstrings = JavaDoc
docstrings = JavaDoc
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package cats.data

private[data] trait ScalaVersionSpecificNonEmptyChainImpl
6 changes: 2 additions & 4 deletions core/src/main/scala/cats/data/NonEmptyChain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] =
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down

0 comments on commit a6e8629

Please sign in to comment.