Skip to content

Commit

Permalink
removed foldRightDefer consistency with foldRight; will break BC with…
Browse files Browse the repository at this point in the history
… it's addition.
  • Loading branch information
gagandeepkalra authored and travisbrown committed Mar 11, 2020
1 parent 74eb85d commit 190981c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/syntax/foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)(
Expand Down
10 changes: 0 additions & 10 deletions laws/src/main/scala/cats/laws/FoldableLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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`
*/
Expand Down
3 changes: 1 addition & 2 deletions laws/src/main/scala/cats/laws/discipline/FoldableTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] _)
)
}

Expand Down

0 comments on commit 190981c

Please sign in to comment.