From 190981c54c851b3406c8cf627e1e5997be6ec7b4 Mon Sep 17 00:00:00 2001 From: Kalra Date: Fri, 6 Mar 2020 22:05:06 +0800 Subject: [PATCH] removed foldRightDefer consistency with foldRight; will break BC with it's addition. --- core/src/main/scala/cats/syntax/foldable.scala | 3 +++ laws/src/main/scala/cats/laws/FoldableLaws.scala | 10 ---------- .../scala/cats/laws/discipline/FoldableTests.scala | 3 +-- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/core/src/main/scala/cats/syntax/foldable.scala b/core/src/main/scala/cats/syntax/foldable.scala index af5bb41524..4fdf6f86e3 100644 --- a/core/src/main/scala/cats/syntax/foldable.scala +++ b/core/src/main/scala/cats/syntax/foldable.scala @@ -332,6 +332,9 @@ final class FoldableOps0[F[_], A](private val fa: F[A]) extends AnyVal { def maximumByOption[B: Order](f: A => B)(implicit F: Foldable[F]): Option[A] = F.maximumOption(fa)(Order.by(f)) + /** + * Implementers are responsible for ensuring they maintain consistency with foldRight; this is not checked by laws on Scala 2.11 + */ def foldRightDefer[G[_]: Defer, B](gb: G[B])(fn: (A, G[B]) => G[B])(implicit F: Foldable[F]): G[B] = Defer[G].defer( F.foldLeft(fa, (z: G[B]) => z)( diff --git a/laws/src/main/scala/cats/laws/FoldableLaws.scala b/laws/src/main/scala/cats/laws/FoldableLaws.scala index ad9096a328..ccb56bd837 100644 --- a/laws/src/main/scala/cats/laws/FoldableLaws.scala +++ b/laws/src/main/scala/cats/laws/FoldableLaws.scala @@ -47,16 +47,6 @@ trait FoldableLaws[F[_]] extends UnorderedFoldableLaws[F] { ): IsEq[B] = F.foldM[Id, A, B](fa, b)(f) <-> F.foldLeft(fa, b)(f) - def foldRightDeferConsistentWithFoldRight[A, B]( - fa: F[A], - f: (B, A) => B - )(implicit - M: Monoid[B]): IsEq[B] = { - val g: (A, Eval[B]) => Eval[B] = (a, ea) => ea.map(f(_, a)) - - F.foldRight(fa, Later(M.empty))(g).value <-> fa.foldRightDefer(Later(M.empty): Eval[B])(g).value - } - /** * `reduceLeftOption` consistent with `reduceLeftToOption` */ diff --git a/laws/src/main/scala/cats/laws/discipline/FoldableTests.scala b/laws/src/main/scala/cats/laws/discipline/FoldableTests.scala index 2689fad9de..2ef720cef2 100644 --- a/laws/src/main/scala/cats/laws/discipline/FoldableTests.scala +++ b/laws/src/main/scala/cats/laws/discipline/FoldableTests.scala @@ -42,8 +42,7 @@ trait FoldableTests[F[_]] extends UnorderedFoldableTests[F] { "takeWhile_ reference" -> forAll(laws.takeWhile_Ref[A] _), "dropWhile_ reference" -> forAll(laws.dropWhile_Ref[A] _), "collectFirstSome reference" -> forAll(laws.collectFirstSome_Ref[A, B] _), - "collectFirst reference" -> forAll(laws.collectFirst_Ref[A, B] _), - "foldRightDefer consistency" -> forAll(laws.foldRightDeferConsistentWithFoldRight[A, B] _) + "collectFirst reference" -> forAll(laws.collectFirst_Ref[A, B] _) ) }