Skip to content

Commit

Permalink
Follow-up #3084 (#3122)
Browse files Browse the repository at this point in the history
* Remove type class constraint from the type class's methods

* Fix documentation

* Change names for consistency
  • Loading branch information
travisbrown authored and kailuowang committed Oct 28, 2019
1 parent 34e7c43 commit 007155f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions core/src/main/scala/cats/Foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,27 @@ 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.
* @see [[maximumByOption]] 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 minimumByOption[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)`.
*
* @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.
* @see [[minimumByOption]] 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 maximumByOption[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`.
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/cats/Reducible.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tests/src/test/scala/cats/tests/FoldableSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 007155f

Please sign in to comment.