From c910cea28083c18f27ed5e4256214c7315384c3e Mon Sep 17 00:00:00 2001 From: Maxim Davydov Date: Mon, 18 Nov 2019 17:57:11 +0300 Subject: [PATCH] #3141 Changed .reduceMap signature --- core/src/main/scala/cats/Reducible.scala | 4 ++-- core/src/main/scala/cats/syntax/reducible.scala | 4 ++-- .../src/test/scala/cats/tests/ReducibleSuite.scala | 13 +++++-------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/core/src/main/scala/cats/Reducible.scala b/core/src/main/scala/cats/Reducible.scala index 5872bf78e6..ba498bc633 100644 --- a/core/src/main/scala/cats/Reducible.scala +++ b/core/src/main/scala/cats/Reducible.scala @@ -97,8 +97,8 @@ import simulacrum.{noop, typeclass} * * `noop` usage description [[https://github.com/typelevel/simulacrum/issues/162 here]] */ - @noop def reduceMapA[G[_], A, B](fga: F[G[A]])(f: A => B)(implicit G: Apply[G], B: Semigroup[B]): G[B] = - reduceLeftTo(fga)(ga => G.map(ga)(f))((gb, ga) => G.map2(gb, G.map(ga)(f))(B.combine)) + @noop def reduceMapA[G[_], A, B](fa: F[A])(f: A => G[B])(implicit G: Apply[G], B: Semigroup[B]): G[B] = + reduceLeftTo(fa)(f)((gb, a) => G.map2(gb, f(a))(B.combine)) /** * Monadic reducing by mapping the `A` values to `G[B]`. combining diff --git a/core/src/main/scala/cats/syntax/reducible.scala b/core/src/main/scala/cats/syntax/reducible.scala index 42cc8dda62..dd8f2b46f4 100644 --- a/core/src/main/scala/cats/syntax/reducible.scala +++ b/core/src/main/scala/cats/syntax/reducible.scala @@ -35,6 +35,6 @@ final class ReducibleOps0[F[_], A](private val fa: F[A]) extends AnyVal { def reduceA[G[_], B](implicit F: Reducible[F], ev: A <:< G[B], G: Apply[G], B: Semigroup[B]): G[B] = F.reduceA[G, B](fa.asInstanceOf[F[G[B]]]) - def reduceMapA[G[_], B, C](f: B => C)(implicit F: Reducible[F], ev: A <:< G[B], G: Apply[G], C: Semigroup[C]): G[C] = - F.reduceMapA[G, B, C](fa.asInstanceOf[F[G[B]]])(f) + def reduceMapA[G[_], B](f: A => G[B])(implicit F: Reducible[F], G: Apply[G], C: Semigroup[B]): G[B] = + F.reduceMapA[G, A, B](fa)(f) } diff --git a/tests/src/test/scala/cats/tests/ReducibleSuite.scala b/tests/src/test/scala/cats/tests/ReducibleSuite.scala index f22e05334c..db786be42a 100644 --- a/tests/src/test/scala/cats/tests/ReducibleSuite.scala +++ b/tests/src/test/scala/cats/tests/ReducibleSuite.scala @@ -102,21 +102,18 @@ abstract class ReducibleSuite[F[_]: Reducible](name: String)(implicit ArbFInt: A } test(s"Reducible[$name].reduceMapA successful case") { - def intToString(i: Int): String = i.toString - val expected = "123" - val actual = - rangeE(1.asRight[String], 2.asRight[String], 3.asRight[String]).reduceMapA(intToString) + val actual = range(1, 3).reduceMapA(_.toString.some) - actual should ===(expected.asRight[String]) + actual should ===(expected.some) } test(s"Reducible[$name].reduceMapA failure case") { - def intToString(i: Int): String = i.toString + def intToString(i: Long): Either[String, Int] = if (i == 2) i.toInt.asRight else "boom!!!".asLeft val expected = "boom!!!" - val actual = rangeE(1.asRight, "boom!!!".asLeft, 3.asRight).reduceMapA(intToString) - actual should ===(expected.asLeft[String]) + val actual = range(1, 3).reduceMapA(intToString) + actual should ===(expected.asLeft[Int]) } test(s"Reducible[$name].toNonEmptyList/toList consistency") {