Skip to content

Commit 007155f

Browse files
travisbrownkailuowang
authored andcommitted
* Remove type class constraint from the type class's methods * Fix documentation * Change names for consistency
1 parent 34e7c43 commit 007155f

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

core/src/main/scala/cats/Foldable.scala

+8-8
Original file line numberDiff line numberDiff line change
@@ -199,27 +199,27 @@ import Foldable.sentinel
199199
* @return `None` if the structure is empty, otherwise the minimum element
200200
* wrapped in a `Some`.
201201
*
202-
* @see [[Reducible#minimum]] for a version that doesn't need to return an
202+
* @see [[Reducible#minimumBy]] for a version that doesn't need to return an
203203
* `Option` for structures that are guaranteed to be non-empty.
204204
*
205-
* @see [[maximumOptionBy]] for maximum instead of minimum.
205+
* @see [[maximumByOption]] for maximum instead of minimum.
206206
*/
207-
def minimumOptionBy[A, B: Order](fa: F[A])(f: A => B)(implicit F: Foldable[F]): Option[A] =
208-
F.minimumOption(fa)(Order.by(f))
207+
def minimumByOption[A, B: Order](fa: F[A])(f: A => B): Option[A] =
208+
minimumOption(fa)(Order.by(f))
209209

210210
/**
211211
* Find the maximum `A` item in this structure according to an `Order.by(f)`.
212212
*
213213
* @return `None` if the structure is empty, otherwise the maximum element
214214
* wrapped in a `Some`.
215215
*
216-
* @see [[Reducible#maximum]] for a version that doesn't need to return an
216+
* @see [[Reducible#maximumBy]] for a version that doesn't need to return an
217217
* `Option` for structures that are guaranteed to be non-empty.
218218
*
219-
* @see [[minimumOptionBy]] for minimum instead of maximum.
219+
* @see [[minimumByOption]] for minimum instead of maximum.
220220
*/
221-
def maximumOptionBy[A, B: Order](fa: F[A])(f: A => B)(implicit F: Foldable[F]): Option[A] =
222-
F.maximumOption(fa)(Order.by(f))
221+
def maximumByOption[A, B: Order](fa: F[A])(f: A => B): Option[A] =
222+
maximumOption(fa)(Order.by(f))
223223

224224
/**
225225
* Get the element at the index of the `Foldable`.

core/src/main/scala/cats/Reducible.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@ import simulacrum.typeclass
161161
*
162162
* @see [[maximumBy]] for maximum instead of minimum.
163163
*/
164-
def minimumBy[A, B: Order](fa: F[A])(f: A => B)(implicit F: Reducible[F]): A =
165-
F.minimum(fa)(Order.by(f))
164+
def minimumBy[A, B: Order](fa: F[A])(f: A => B): A =
165+
minimum(fa)(Order.by(f))
166166

167167
/**
168168
* Find the maximum `A` item in this structure according to an `Order.by(f)`.
169169
*
170170
* @see [[minimumBy]] for minimum instead of maximum.
171171
*/
172-
def maximumBy[A, B: Order](fa: F[A])(f: A => B)(implicit F: Reducible[F]): A =
173-
F.maximum(fa)(Order.by(f))
172+
def maximumBy[A, B: Order](fa: F[A])(f: A => B): A =
173+
maximum(fa)(Order.by(f))
174174

175175
/**
176176
* Intercalate/insert an element between the existing elements while reducing.

tests/src/test/scala/cats/tests/FoldableSuite.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ abstract class FoldableSuite[F[_]: Foldable](name: String)(implicit ArbFInt: Arb
194194

195195
test(s"Foldable[$name].maximumBy/minimumBy") {
196196
forAll { (fa: F[Int], f: Int => Int) =>
197-
val maxOpt = fa.maximumOptionBy(f).map(f)
198-
val minOpt = fa.minimumOptionBy(f).map(f)
197+
val maxOpt = fa.maximumByOption(f).map(f)
198+
val minOpt = fa.minimumByOption(f).map(f)
199199
val nelOpt = fa.toList.toNel
200200
maxOpt should ===(nelOpt.map(_.maximumBy(f)).map(f))
201201
maxOpt should ===(nelOpt.map(_.toList.maxBy(f)).map(f))

0 commit comments

Comments
 (0)