Skip to main content

minBy

For any types T and K,

minBy(collection: Bag<T>,  keySelector: T -> K) : T?

Gets the least item in the collection, where items are ordered by the value returned by applying selector to each item.

  • For example, if the following function has been declared getRoutePrefix(route) = route.prefix;, and if routes is a variable referring to some list of IpEntry records, then minBy(routes, getRoutePrefix) evaluates to the route with the smallest prefix (aka subnet). See how comparisons work for more on how subnets are ordered.
  • Similar to max and min, this function returns null if there are no items in the collection.
  • Note that this method accepts both Lists and Bags ─since Lists subtype Bags

See also

Types

Functions