All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nield.kotlinstatistics.ComparableStatistics.kt Maven / Gradle / Ivy

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)





© 2015 - 2024 Weber Informatics LLC | Privacy Policy