From a6e85dd543cc21cc36323b25371237eab825751e Mon Sep 17 00:00:00 2001 From: Kailuo Wang Date: Mon, 23 Oct 2017 13:21:51 -0400 Subject: [PATCH] address feedback / removed duplicated class --- .../main/scala/alleycats/std/iterable.scala | 15 ++-------- .../src/main/scala/alleycats/std/set.scala | 2 +- .../scala/alleycats/syntax/foldable.scala | 2 +- .../alleycats/tests/AlleycatsSuite.scala | 2 +- .../scala/alleycats/tests/CatsEquality.scala | 30 ------------------- 5 files changed, 5 insertions(+), 46 deletions(-) delete mode 100644 alleycats-tests/src/test/scala/alleycats/tests/CatsEquality.scala diff --git a/alleycats-core/src/main/scala/alleycats/std/iterable.scala b/alleycats-core/src/main/scala/alleycats/std/iterable.scala index c58e551d22..7ccde80e75 100644 --- a/alleycats-core/src/main/scala/alleycats/std/iterable.scala +++ b/alleycats-core/src/main/scala/alleycats/std/iterable.scala @@ -14,19 +14,8 @@ object IterableInstances { new Foldable[Iterable] { override def foldLeft[A, B](fa: Iterable[A], b: B)(f: (B, A) => B): B = fa.foldLeft(b)(f) - // based upon foldRight of List in Cats - override def foldRight[A, B](fa: Iterable[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] = { - def loop(as: Iterable[A]): Eval[B] = - if (as.isEmpty) - lb - else { - val h = as.head - val t = as.tail - f(h, Eval.defer(loop(t))) - } - Eval.defer(loop(fa)) - } - + override def foldRight[A, B](fa: Iterable[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] = + Foldable.iterateRight(fa, lb)(f) } } diff --git a/alleycats-core/src/main/scala/alleycats/std/set.scala b/alleycats-core/src/main/scala/alleycats/std/set.scala index 8af2432628..da851068e4 100644 --- a/alleycats-core/src/main/scala/alleycats/std/set.scala +++ b/alleycats-core/src/main/scala/alleycats/std/set.scala @@ -66,7 +66,7 @@ object SetInstances { def foldLeft[A, B](fa: Set[A], b: B)(f: (B, A) => B): B = fa.foldLeft(b)(f) def foldRight[A, B](fa: Set[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] = - Foldable.iterateRight(fa.iterator, lb)(f) + Foldable.iterateRight(fa, lb)(f) def traverse[G[_]: Applicative, A, B](sa: Set[A])(f: A => G[B]): G[Set[B]] = { val G = Applicative[G] sa.foldLeft(G.pure(Set.empty[B])) { (buf, a) => diff --git a/alleycats-core/src/main/scala/alleycats/syntax/foldable.scala b/alleycats-core/src/main/scala/alleycats/syntax/foldable.scala index 687209e8a4..ddcbce70b2 100644 --- a/alleycats-core/src/main/scala/alleycats/syntax/foldable.scala +++ b/alleycats-core/src/main/scala/alleycats/syntax/foldable.scala @@ -9,6 +9,6 @@ object foldable extends FoldableSyntax trait FoldableSyntax { implicit class ExtraFoldableOps[F[_]: Foldable, A](fa: F[A]) { def foreach(f: A => Unit): Unit = - fa.foldLeft(()) { (unit, a) => f(a); unit } + fa.foldLeft(()) { (_, a) => f(a) } } } diff --git a/alleycats-tests/src/test/scala/alleycats/tests/AlleycatsSuite.scala b/alleycats-tests/src/test/scala/alleycats/tests/AlleycatsSuite.scala index a558397a7a..9ced1461bc 100644 --- a/alleycats-tests/src/test/scala/alleycats/tests/AlleycatsSuite.scala +++ b/alleycats-tests/src/test/scala/alleycats/tests/AlleycatsSuite.scala @@ -7,7 +7,7 @@ import catalysts.Platform import cats._ import cats.instances.AllInstances import cats.syntax.{AllSyntax, EqOps} - +import cats.tests.StrictCatsEquality import org.scalactic.anyvals.{PosZDouble, PosInt, PosZInt} import org.scalatest.{FunSuite, Matchers} import org.scalatest.prop.{Configuration, GeneratorDrivenPropertyChecks} diff --git a/alleycats-tests/src/test/scala/alleycats/tests/CatsEquality.scala b/alleycats-tests/src/test/scala/alleycats/tests/CatsEquality.scala deleted file mode 100644 index f4a9abb2cc..0000000000 --- a/alleycats-tests/src/test/scala/alleycats/tests/CatsEquality.scala +++ /dev/null @@ -1,30 +0,0 @@ -package alleycats.tests - -import cats._ - -import org.scalactic._ -import TripleEqualsSupport.AToBEquivalenceConstraint -import TripleEqualsSupport.BToAEquivalenceConstraint - -// The code in this file was taken and only slightly modified from -// https://github.com/bvenners/equality-integration-demo -// Thanks for the great examples, Bill! - -final class CatsEquivalence[T](T: Eq[T]) extends Equivalence[T] { - def areEquivalent(a: T, b: T): Boolean = T.eqv(a, b) -} - -trait LowPriorityStrictCatsConstraints extends TripleEquals { - implicit def lowPriorityCatsCanEqual[A, B](implicit B: Eq[B], ev: A <:< B): CanEqual[A, B] = - new AToBEquivalenceConstraint[A, B](new CatsEquivalence(B), ev) -} - -trait StrictCatsEquality extends LowPriorityStrictCatsConstraints { - override def convertToEqualizer[T](left: T): Equalizer[T] = super.convertToEqualizer[T](left) - implicit override def convertToCheckingEqualizer[T](left: T): CheckingEqualizer[T] = new CheckingEqualizer(left) - override def unconstrainedEquality[A, B](implicit equalityOfA: Equality[A]): CanEqual[A, B] = super.unconstrainedEquality[A, B] - implicit def catsCanEqual[A, B](implicit A: Eq[A], ev: B <:< A): CanEqual[A, B] = - new BToAEquivalenceConstraint[A, B](new CatsEquivalence(A), ev) -} - -object StrictCatsEquality extends StrictCatsEquality