org.nield.kotlinstatistics.ComparableStatistics.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-statistics Show documentation
Show all versions of kotlin-statistics Show documentation
Statistical and analytical extensions for Kotlin
The newest version!
package org.nield.kotlinstatistics
inline fun ,K> Sequence.minBy(crossinline keySelector: (T) -> K, crossinline valueSelector: (T) -> R) =
groupApply(keySelector, valueSelector) { it.min() }
inline fun ,K> Iterable.minBy(crossinline keySelector: (T) -> K, crossinline valueSelector: (T) -> R) =
asSequence().minBy(keySelector, valueSelector)
fun > Sequence>.minBy() =
groupApply({it.first}, {it.second}) { it.min() }
fun > Iterable>.minBy() = asSequence().minBy()
inline fun ,K> Sequence.maxBy(crossinline keySelector: (T) -> K, crossinline valueSelector: (T) -> R) =
groupApply(keySelector, valueSelector) { it.max() }
inline fun ,K> Iterable.maxBy(crossinline keySelector: (T) -> K, crossinline valueSelector: (T) -> R) =
asSequence().maxBy(keySelector, valueSelector)
fun ,K> Sequence>.maxBy() =
groupApply({it.first}, {it.second}) { it.max() }
fun ,K> Iterable>.maxBy() = asSequence().maxBy()
fun > Sequence.range() = toList().range()
fun > Iterable.range() = toList().let { (it.min()?:throw Exception("At least one element must be present"))..(it.max()?:throw Exception("At least one element must be present")) }
inline fun ,K> Sequence.rangeBy(crossinline keySelector: (T) -> K, crossinline valueSelector: (T) -> R) =
groupApply(keySelector, valueSelector) { it.range() }
inline fun ,K> Iterable.rangeBy(crossinline keySelector: (T) -> K, crossinline valueSelector: (T) -> R) =
asSequence().rangeBy(keySelector, valueSelector)