maxBy
For any types T and K,
maxBy(collection: Bag<T>, keySelector: T -> K) : T?
Gets the greatest item in the collection, where items are ordered by the value returned by applying keySelector to
the item.
- For example, if the following function has been declared
getRoutePrefix(route) = route.prefix;, and ifroutesis a variable referring to some list ofIpEntryrecords, thenmaxBy(routes, getRoutePrefix)evaluates to the route with the largest prefix (aka subnet). See how comparisons work for more on how subnets are ordered. - Similar to
maxandmin, this function returnsnullif there are no items in the collection. - Note that this method accepts both
ListsandBags─since Lists subtype Bags