Skip to content

Commit

Permalink
removed reduceRightK
Browse files Browse the repository at this point in the history
  • Loading branch information
kailuowang committed Dec 7, 2017
1 parent 9410809 commit 7796307
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 30 deletions.
4 changes: 1 addition & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,7 @@ def mimaSettings(moduleName: String) = Seq(
exclude[ReversedMissingMethodProblem]("cats.MonadError.rethrow"),
exclude[ReversedMissingMethodProblem]("cats.syntax.MonadErrorSyntax.catsSyntaxMonadErrorRethrow"),
exclude[DirectMissingMethodProblem]("cats.data.CokleisliArrow.id"),
exclude[IncompatibleResultTypeProblem]("cats.data.CokleisliArrow.id"),
exclude[ReversedMissingMethodProblem]("cats.Foldable.reduceRightK"),
exclude[ReversedMissingMethodProblem]("cats.Foldable#Ops.reduceRightK")
exclude[IncompatibleResultTypeProblem]("cats.data.CokleisliArrow.id")
)
}
)
Expand Down
18 changes: 0 additions & 18 deletions core/src/main/scala/cats/Foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -244,24 +244,6 @@ import Foldable.sentinel
A.combine(acc, a)
}

/**
* Like `foldK` but from the right side.
* One use case would be endo functions (`A => A`) chaining
* because the default MonoidK instance for endo functions
* is using `compose` rather than the `andThen`
* {{{
* scala> import cats.implicits._, cats.Endo
* scala> val l: List[Endo[Int]] = List(_ * 2, _ + 3)
* scala> val f = l.reduceRightK //using `compose` to chain the functions
* scala> f(1)
* res0: Int = 5
* }}}
*/
def reduceRightK[G[_], A](fga: F[G[A]])(implicit G: MonoidK[G]): G[A] =
foldRight(fga, Eval.now(G.empty[A])) { (ga, ega) =>
ega.map(rga => G.combineK(rga, ga))
}.value

/**
* Alias for [[fold]].
*/
Expand Down
9 changes: 1 addition & 8 deletions tests/src/test/scala/cats/tests/FoldableSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import cats.laws.discipline.arbitrary._

abstract class FoldableSuite[F[_]: Foldable](name: String)(
implicit ArbFInt: Arbitrary[F[Int]],
ArbFString: Arbitrary[F[String]],
ArbFListString: Arbitrary[F[List[String]]]) extends CatsSuite with PropertyChecks {
ArbFString: Arbitrary[F[String]]) extends CatsSuite with PropertyChecks {

def iterator[T](fa: F[T]): Iterator[T]

Expand All @@ -36,12 +35,6 @@ abstract class FoldableSuite[F[_]: Foldable](name: String)(
}
}

test("Foldable#reduceRightK") {
forAll { (fi: F[List[String]]) =>
fi.reduceRightK should === (fi.foldRight(Eval.now(List.empty[String]))((l, el) => el.map(_ ++ l)).value)
}
}

test("Foldable#partitionEither consistent with List#partition") {
forAll { (fi: F[Int], f: Int => Either[String, String]) =>
val list = Foldable[F].toList(fi)
Expand Down
5 changes: 4 additions & 1 deletion tests/src/test/scala/cats/tests/ReducibleSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ class ReducibleSuiteAdditional extends CatsSuite {

}

abstract class ReducibleSuite[F[_]: Reducible](name: String)(implicit ArbFInt: Arbitrary[F[Int]], ArbFString: Arbitrary[F[String]], ArbFListString: Arbitrary[F[List[String]]]) extends FoldableSuite[F](name) {
abstract class ReducibleSuite[F[_]: Reducible](name: String)(
implicit ArbFInt: Arbitrary[F[Int]],
ArbFString: Arbitrary[F[String]]) extends FoldableSuite[F](name) {

def range(start: Long, endInclusive: Long): F[Long]

test(s"Reducible[$name].reduceLeftM stack safety") {
Expand Down

0 comments on commit 7796307

Please sign in to comment.