Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NonEmptyChain.fromSeq signature on 2.12 #3133

Merged
merged 4 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -109,7 +109,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