21 lines
738 B
Kotlin
21 lines
738 B
Kotlin
package moe.kageru.spektacles
|
|
|
|
import arrow.Kind
|
|
import arrow.typeclasses.Functor
|
|
import java.time.Month
|
|
|
|
fun ParsedLines.heatMapByHour(): SortedCounter<Int> = heatMapBy { it.time.hour }
|
|
|
|
fun ParsedLines.heatMapByMinute(): SortedCounter<Int> = heatMapBy { it.time.hour * 100 + it.time.minute }
|
|
|
|
fun ParsedLines.heatMapByMonth(): SortedCounter<Month> = heatMapBy { it.time.month }
|
|
|
|
private fun <T: Comparable<T>>ParsedLines.heatMapBy(op: (ParsedLine) -> T): SortedCounter<T> {
|
|
return this.map(op)
|
|
.asIterable()
|
|
.toSortedCounter()
|
|
}
|
|
|
|
inline fun <F, reified A, R> Kind<F, Kind<F, A>>.deepMap(noinline op: (A) -> R, AP: Functor<F>): Kind<F, Kind<F, R>> =
|
|
AP.run { this@deepMap.map { nested: Kind<F, A> -> nested.map(op) } }
|