From e7302153449b2904b59614ad8f04169c63083b00 Mon Sep 17 00:00:00 2001 From: Travis Brown Date: Mon, 28 Oct 2019 08:52:10 -0500 Subject: [PATCH 1/3] Remove type class constraint from the type class's methods --- core/src/main/scala/cats/Foldable.scala | 8 ++++---- core/src/main/scala/cats/Reducible.scala | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/main/scala/cats/Foldable.scala b/core/src/main/scala/cats/Foldable.scala index b0a5fb2701..0311181c54 100644 --- a/core/src/main/scala/cats/Foldable.scala +++ b/core/src/main/scala/cats/Foldable.scala @@ -204,8 +204,8 @@ import Foldable.sentinel * * @see [[maximumOptionBy]] for maximum instead of minimum. */ - def minimumOptionBy[A, B: Order](fa: F[A])(f: A => B)(implicit F: Foldable[F]): Option[A] = - F.minimumOption(fa)(Order.by(f)) + def minimumOptionBy[A, B: Order](fa: F[A])(f: A => B): Option[A] = + minimumOption(fa)(Order.by(f)) /** * Find the maximum `A` item in this structure according to an `Order.by(f)`. @@ -218,8 +218,8 @@ import Foldable.sentinel * * @see [[minimumOptionBy]] for minimum instead of maximum. */ - def maximumOptionBy[A, B: Order](fa: F[A])(f: A => B)(implicit F: Foldable[F]): Option[A] = - F.maximumOption(fa)(Order.by(f)) + def maximumOptionBy[A, B: Order](fa: F[A])(f: A => B): Option[A] = + maximumOption(fa)(Order.by(f)) /** * Get the element at the index of the `Foldable`. diff --git a/core/src/main/scala/cats/Reducible.scala b/core/src/main/scala/cats/Reducible.scala index a0e60b2cb5..f41161b558 100644 --- a/core/src/main/scala/cats/Reducible.scala +++ b/core/src/main/scala/cats/Reducible.scala @@ -161,16 +161,16 @@ import simulacrum.typeclass * * @see [[maximumBy]] for maximum instead of minimum. */ - def minimumBy[A, B: Order](fa: F[A])(f: A => B)(implicit F: Reducible[F]): A = - F.minimum(fa)(Order.by(f)) + def minimumBy[A, B: Order](fa: F[A])(f: A => B): A = + minimum(fa)(Order.by(f)) /** * Find the maximum `A` item in this structure according to an `Order.by(f)`. * * @see [[minimumBy]] for minimum instead of maximum. */ - def maximumBy[A, B: Order](fa: F[A])(f: A => B)(implicit F: Reducible[F]): A = - F.maximum(fa)(Order.by(f)) + def maximumBy[A, B: Order](fa: F[A])(f: A => B): A = + maximum(fa)(Order.by(f)) /** * Intercalate/insert an element between the existing elements while reducing. From e16ac5d154c950c898b511c516c94f79aba2136f Mon Sep 17 00:00:00 2001 From: Travis Brown Date: Mon, 28 Oct 2019 08:53:17 -0500 Subject: [PATCH 2/3] Fix documentation --- core/src/main/scala/cats/Foldable.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/cats/Foldable.scala b/core/src/main/scala/cats/Foldable.scala index 0311181c54..a7fd2af423 100644 --- a/core/src/main/scala/cats/Foldable.scala +++ b/core/src/main/scala/cats/Foldable.scala @@ -199,7 +199,7 @@ import Foldable.sentinel * @return `None` if the structure is empty, otherwise the minimum element * wrapped in a `Some`. * - * @see [[Reducible#minimum]] for a version that doesn't need to return an + * @see [[Reducible#minimumBy]] for a version that doesn't need to return an * `Option` for structures that are guaranteed to be non-empty. * * @see [[maximumOptionBy]] for maximum instead of minimum. @@ -213,7 +213,7 @@ import Foldable.sentinel * @return `None` if the structure is empty, otherwise the maximum element * wrapped in a `Some`. * - * @see [[Reducible#maximum]] for a version that doesn't need to return an + * @see [[Reducible#maximumBy]] for a version that doesn't need to return an * `Option` for structures that are guaranteed to be non-empty. * * @see [[minimumOptionBy]] for minimum instead of maximum. From 377b0a52230cd72dd45d43af0a4db2139bd65200 Mon Sep 17 00:00:00 2001 From: Travis Brown Date: Mon, 28 Oct 2019 08:55:04 -0500 Subject: [PATCH 3/3] Change names for consistency --- core/src/main/scala/cats/Foldable.scala | 8 ++++---- tests/src/test/scala/cats/tests/FoldableSuite.scala | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/scala/cats/Foldable.scala b/core/src/main/scala/cats/Foldable.scala index a7fd2af423..0e2d8b69e5 100644 --- a/core/src/main/scala/cats/Foldable.scala +++ b/core/src/main/scala/cats/Foldable.scala @@ -202,9 +202,9 @@ import Foldable.sentinel * @see [[Reducible#minimumBy]] for a version that doesn't need to return an * `Option` for structures that are guaranteed to be non-empty. * - * @see [[maximumOptionBy]] for maximum instead of minimum. + * @see [[maximumByOption]] for maximum instead of minimum. */ - def minimumOptionBy[A, B: Order](fa: F[A])(f: A => B): Option[A] = + def minimumByOption[A, B: Order](fa: F[A])(f: A => B): Option[A] = minimumOption(fa)(Order.by(f)) /** @@ -216,9 +216,9 @@ import Foldable.sentinel * @see [[Reducible#maximumBy]] for a version that doesn't need to return an * `Option` for structures that are guaranteed to be non-empty. * - * @see [[minimumOptionBy]] for minimum instead of maximum. + * @see [[minimumByOption]] for minimum instead of maximum. */ - def maximumOptionBy[A, B: Order](fa: F[A])(f: A => B): Option[A] = + def maximumByOption[A, B: Order](fa: F[A])(f: A => B): Option[A] = maximumOption(fa)(Order.by(f)) /** diff --git a/tests/src/test/scala/cats/tests/FoldableSuite.scala b/tests/src/test/scala/cats/tests/FoldableSuite.scala index 6da3d78b09..addf449232 100644 --- a/tests/src/test/scala/cats/tests/FoldableSuite.scala +++ b/tests/src/test/scala/cats/tests/FoldableSuite.scala @@ -194,8 +194,8 @@ abstract class FoldableSuite[F[_]: Foldable](name: String)(implicit ArbFInt: Arb test(s"Foldable[$name].maximumBy/minimumBy") { forAll { (fa: F[Int], f: Int => Int) => - val maxOpt = fa.maximumOptionBy(f).map(f) - val minOpt = fa.minimumOptionBy(f).map(f) + val maxOpt = fa.maximumByOption(f).map(f) + val minOpt = fa.minimumByOption(f).map(f) val nelOpt = fa.toList.toNel maxOpt should ===(nelOpt.map(_.maximumBy(f)).map(f)) maxOpt should ===(nelOpt.map(_.toList.maxBy(f)).map(f))