Skip to content

Commit

Permalink
remove zipWithIndexNE
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek committed Jul 27, 2020
1 parent 561dd5e commit f4791f9
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions core/src/main/scala/cats/data/Chain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,11 @@ sealed abstract class Chain[+A] {
*/
final def zipWithIndex: Chain[(A, Int)] =
this match {
case non: Chain.NonEmpty[A] => non.zipWithIndexNE
case _ => Empty
case Singleton(a) => Singleton((a, 0))
case a @ Append(_, _) =>
Wrap(a.iterator.zipWithIndex.toVector)
case Wrap(seq) => Wrap(seq.zipWithIndex)
case _ => Empty
}

/**
Expand Down Expand Up @@ -588,15 +591,7 @@ object Chain extends ChainInstances {

private val sentinel: Function1[Any, Any] = new scala.runtime.AbstractFunction1[Any, Any] { def apply(a: Any) = this }

sealed abstract private[data] class NonEmpty[A] extends Chain[A] {
final def zipWithIndexNE: NonEmpty[(A, Int)] =
this match {
case Singleton(a) => Singleton((a, 0))
case a @ Append(_, _) =>
Wrap(a.iterator.zipWithIndex.toVector)
case Wrap(seq) => Wrap(seq.zipWithIndex)
}
}
sealed abstract private[data] class NonEmpty[A] extends Chain[A]

private[data] case object Empty extends Chain[Nothing]
final private[data] case class Singleton[A](a: A) extends NonEmpty[A]
Expand Down

0 comments on commit f4791f9

Please sign in to comment.