KT-20357 Add samples for maxBy and minBy

This commit is contained in:
Karen Schwane
2018-10-31 08:21:30 +01:00
committed by ilya-g
parent aae24c993d
commit d88fd8aa6f
7 changed files with 76 additions and 0 deletions
@@ -147,6 +147,8 @@ public inline fun <K, V> Map<out K, V>.forEach(action: (Map.Entry<K, V>) -> Unit
/**
* Returns the first entry yielding the largest value of the given function or `null` if there are no entries.
*
* @sample samples.collections.Collections.Aggregates.maxBy
*/
@kotlin.internal.InlineOnly
public inline fun <K, V, R : Comparable<R>> Map<out K, V>.maxBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>? {
@@ -163,6 +165,8 @@ public inline fun <K, V> Map<out K, V>.maxWith(comparator: Comparator<in Map.Ent
/**
* Returns the first entry yielding the smallest value of the given function or `null` if there are no entries.
*
* @sample samples.collections.Collections.Aggregates.minBy
*/
public inline fun <K, V, R : Comparable<R>> Map<out K, V>.minBy(selector: (Map.Entry<K, V>) -> R): Map.Entry<K, V>? {
return entries.minBy(selector)