From 86636fed3fbc5bd15d554c57cf8294380972221c Mon Sep 17 00:00:00 2001 From: "ta.tanaka" Date: Thu, 8 Aug 2019 19:11:00 +0900 Subject: [PATCH] Remove redundant type annotation. --- .../cats/data/AbstractNonEmptyInstances.scala | 7 ++++--- .../main/scala/cats/data/NonEmptyChain.scala | 8 +++++-- .../main/scala/cats/data/NonEmptyList.scala | 21 ++++++++----------- .../main/scala/cats/data/NonEmptyVector.scala | 21 ++++++++----------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/core/src/main/scala/cats/data/AbstractNonEmptyInstances.scala b/core/src/main/scala/cats/data/AbstractNonEmptyInstances.scala index 57a65ecf429..537fd7499b4 100644 --- a/core/src/main/scala/cats/data/AbstractNonEmptyInstances.scala +++ b/core/src/main/scala/cats/data/AbstractNonEmptyInstances.scala @@ -5,7 +5,8 @@ abstract private[data] class AbstractNonEmptyInstances[F[_], NonEmptyF[_]](impli CF: CoflatMap[F], TF: Traverse[F], SF: SemigroupK[F]) - extends Bimonad[NonEmptyF] + extends NonEmptyReducible[NonEmptyF, F] + with Bimonad[NonEmptyF] with NonEmptyTraverse[NonEmptyF] with SemigroupK[NonEmptyF] { val monadInstance = MF.asInstanceOf[Monad[NonEmptyF]] @@ -35,10 +36,10 @@ abstract private[data] class AbstractNonEmptyInstances[F[_], NonEmptyF[_]](impli def tailRecM[A, B](a: A)(f: A => NonEmptyF[Either[A, B]]): NonEmptyF[B] = monadInstance.tailRecM(a)(f) - def foldLeft[A, B](fa: NonEmptyF[A], b: B)(f: (B, A) => B): B = + override def foldLeft[A, B](fa: NonEmptyF[A], b: B)(f: (B, A) => B): B = traverseInstance.foldLeft(fa, b)(f) - def foldRight[A, B](fa: NonEmptyF[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] = + override def foldRight[A, B](fa: NonEmptyF[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] = traverseInstance.foldRight(fa, lb)(f) override def foldMap[A, B](fa: NonEmptyF[A])(f: A => B)(implicit B: Monoid[B]): B = diff --git a/core/src/main/scala/cats/data/NonEmptyChain.scala b/core/src/main/scala/cats/data/NonEmptyChain.scala index 4756e37e38b..912f4000d6f 100644 --- a/core/src/main/scala/cats/data/NonEmptyChain.scala +++ b/core/src/main/scala/cats/data/NonEmptyChain.scala @@ -442,12 +442,16 @@ sealed abstract private[data] class NonEmptyChainInstances extends NonEmptyChain override def reduce[A](fa: NonEmptyChain[A])(implicit A: Semigroup[A]): A = fa.reduce - def reduceLeftTo[A, B](fa: NonEmptyChain[A])(f: A => B)(g: (B, A) => B): B = fa.reduceLeftTo(f)(g) + override def reduceLeftTo[A, B](fa: NonEmptyChain[A])(f: A => B)(g: (B, A) => B): B = fa.reduceLeftTo(f)(g) - def reduceRightTo[A, B](fa: NonEmptyChain[A])(f: A => B)(g: (A, cats.Eval[B]) => cats.Eval[B]): cats.Eval[B] = + override def reduceRightTo[A, B]( + fa: NonEmptyChain[A] + )(f: A => B)(g: (A, cats.Eval[B]) => cats.Eval[B]): cats.Eval[B] = Eval.defer(fa.reduceRightTo(a => Eval.now(f(a))) { (a, b) => Eval.defer(g(a, b)) }) + + def split[A](fa: NonEmptyChain[A]): (A, Chain[A]) = fa.uncons } implicit def catsDataOrderForNonEmptyChain[A: Order]: Order[NonEmptyChain[A]] = diff --git a/core/src/main/scala/cats/data/NonEmptyList.scala b/core/src/main/scala/cats/data/NonEmptyList.scala index 89ebe57cd3e..0e5937c715b 100644 --- a/core/src/main/scala/cats/data/NonEmptyList.scala +++ b/core/src/main/scala/cats/data/NonEmptyList.scala @@ -506,14 +506,11 @@ object NonEmptyList extends NonEmptyListInstances { sealed abstract private[data] class NonEmptyListInstances extends NonEmptyListInstances0 { - implicit val catsDataInstancesForNonEmptyList: SemigroupK[NonEmptyList] - with Reducible[NonEmptyList] - with Bimonad[NonEmptyList] - with NonEmptyTraverse[NonEmptyList] = - new NonEmptyReducible[NonEmptyList, List] with SemigroupK[NonEmptyList] with Bimonad[NonEmptyList] - with NonEmptyTraverse[NonEmptyList] { - - def combineK[A](a: NonEmptyList[A], b: NonEmptyList[A]): NonEmptyList[A] = + implicit val catsDataInstancesForNonEmptyList + : SemigroupK[NonEmptyList] with Bimonad[NonEmptyList] with NonEmptyTraverse[NonEmptyList] = + new AbstractNonEmptyInstances[List, NonEmptyList] { + + override def combineK[A](a: NonEmptyList[A], b: NonEmptyList[A]): NonEmptyList[A] = a.concatNel(b) override def split[A](fa: NonEmptyList[A]): (A, List[A]) = (fa.head, fa.tail) @@ -527,13 +524,13 @@ sealed abstract private[data] class NonEmptyListInstances extends NonEmptyListIn override def map[A, B](fa: NonEmptyList[A])(f: A => B): NonEmptyList[B] = fa.map(f) - def pure[A](x: A): NonEmptyList[A] = + override def pure[A](x: A): NonEmptyList[A] = NonEmptyList.one(x) - def flatMap[A, B](fa: NonEmptyList[A])(f: A => NonEmptyList[B]): NonEmptyList[B] = + override def flatMap[A, B](fa: NonEmptyList[A])(f: A => NonEmptyList[B]): NonEmptyList[B] = fa.flatMap(f) - def coflatMap[A, B](fa: NonEmptyList[A])(f: NonEmptyList[A] => B): NonEmptyList[B] = + override def coflatMap[A, B](fa: NonEmptyList[A])(f: NonEmptyList[A] => B): NonEmptyList[B] = fa.coflatMap(f) def extract[A](fa: NonEmptyList[A]): A = fa.head @@ -563,7 +560,7 @@ sealed abstract private[data] class NonEmptyListInstances extends NonEmptyListIn override def foldMap[A, B](fa: NonEmptyList[A])(f: A => B)(implicit B: Monoid[B]): B = B.combineAll(fa.toList.iterator.map(f)) - def tailRecM[A, B](a: A)(f: A => NonEmptyList[Either[A, B]]): NonEmptyList[B] = { + override def tailRecM[A, B](a: A)(f: A => NonEmptyList[Either[A, B]]): NonEmptyList[B] = { val buf = new ListBuffer[B] @tailrec def go(v: NonEmptyList[Either[A, B]]): Unit = v.head match { case Right(b) => diff --git a/core/src/main/scala/cats/data/NonEmptyVector.scala b/core/src/main/scala/cats/data/NonEmptyVector.scala index d0d94b3e69f..c43cf7f4a64 100644 --- a/core/src/main/scala/cats/data/NonEmptyVector.scala +++ b/core/src/main/scala/cats/data/NonEmptyVector.scala @@ -238,14 +238,11 @@ final class NonEmptyVector[+A] private (val toVector: Vector[A]) extends AnyVal @suppressUnusedImportWarningForScalaVersionSpecific sealed abstract private[data] class NonEmptyVectorInstances { - implicit val catsDataInstancesForNonEmptyVector: SemigroupK[NonEmptyVector] - with Reducible[NonEmptyVector] - with Bimonad[NonEmptyVector] - with NonEmptyTraverse[NonEmptyVector] = - new NonEmptyReducible[NonEmptyVector, Vector] with SemigroupK[NonEmptyVector] with Bimonad[NonEmptyVector] - with NonEmptyTraverse[NonEmptyVector] { - - def combineK[A](a: NonEmptyVector[A], b: NonEmptyVector[A]): NonEmptyVector[A] = + implicit val catsDataInstancesForNonEmptyVector + : SemigroupK[NonEmptyVector] with Bimonad[NonEmptyVector] with NonEmptyTraverse[NonEmptyVector] = + new AbstractNonEmptyInstances[Vector, NonEmptyVector] { + + override def combineK[A](a: NonEmptyVector[A], b: NonEmptyVector[A]): NonEmptyVector[A] = a.concatNev(b) override def split[A](fa: NonEmptyVector[A]): (A, Vector[A]) = (fa.head, fa.tail) @@ -261,13 +258,13 @@ sealed abstract private[data] class NonEmptyVectorInstances { override def map[A, B](fa: NonEmptyVector[A])(f: A => B): NonEmptyVector[B] = fa.map(f) - def pure[A](x: A): NonEmptyVector[A] = + override def pure[A](x: A): NonEmptyVector[A] = NonEmptyVector.one(x) - def flatMap[A, B](fa: NonEmptyVector[A])(f: A => NonEmptyVector[B]): NonEmptyVector[B] = + override def flatMap[A, B](fa: NonEmptyVector[A])(f: A => NonEmptyVector[B]): NonEmptyVector[B] = fa.flatMap(f) - def coflatMap[A, B](fa: NonEmptyVector[A])(f: NonEmptyVector[A] => B): NonEmptyVector[B] = { + override def coflatMap[A, B](fa: NonEmptyVector[A])(f: NonEmptyVector[A] => B): NonEmptyVector[B] = { @tailrec def consume(as: Vector[A], buf: VectorBuilder[B]): Vector[B] = as match { case a +: as => consume(as, buf += f(NonEmptyVector(a, as))) @@ -329,7 +326,7 @@ sealed abstract private[data] class NonEmptyVectorInstances { override def get[A](fa: NonEmptyVector[A])(idx: Long): Option[A] = if (0 <= idx && idx < Int.MaxValue) fa.get(idx.toInt) else None - def tailRecM[A, B](a: A)(f: A => NonEmptyVector[Either[A, B]]): NonEmptyVector[B] = { + override def tailRecM[A, B](a: A)(f: A => NonEmptyVector[Either[A, B]]): NonEmptyVector[B] = { val buf = new VectorBuilder[B] @tailrec def go(v: NonEmptyVector[Either[A, B]]): Unit = v.head match { case Right(b) =>