> For the complete documentation index, see [llms.txt](https://www.selinux.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.selinux.tech/scala/function-operation/m/maxby.md).

# maxBy

## definition

```scala
def maxBy[B](f: (A) ⇒ B): A
```

## demo

```scala
case class Donut(name: String, price: Double)

val donuts: Seq[Donut] = Seq(Donut("Plain Donut", 1.5), Donut("Strawberry Donut", 2.0), Donut("Glazed Donut", 2.5))

// find the maximum element in a sequence of case classes objects using the maxBy function
val max1 = donuts.maxBy(donut => donut.price)


// declare a value predicate function for maxBy function
val donutsMaxBy: (Donut) => Double = (donut) => donut.price
val max2 = donuts.maxBy(donutsMaxBy)
```
