60 lines
1.6 KiB
Kotlin
60 lines
1.6 KiB
Kotlin
package moe.kageru.spektacles
|
|
|
|
import arrow.Kind
|
|
import arrow.core.*
|
|
import arrow.core.extensions.mapk.functor.functor
|
|
import arrow.typeclasses.Functor
|
|
import moe.kageru.spektacles.Node.Leaf
|
|
import java.time.Month
|
|
import kotlin.system.measureTimeMillis
|
|
|
|
fun main() {
|
|
val time = measureTimeMillis {
|
|
spektacle()
|
|
}
|
|
println("Time spent: $time ms")
|
|
}
|
|
|
|
fun spektacle() {
|
|
IoHandler.readFile("test.log")
|
|
.parse()
|
|
.filterUsers("kageru_").toList().k()
|
|
.let<List<ParsedLine>, Node<ParsedLine>>(::Leaf)
|
|
//.grouped { it.time.year }
|
|
//.mapValues { it.value.groupBy { it.time.month } }.k()
|
|
//.ap(mapOf(
|
|
//1 to { lines: Map<Month, List<ParsedLine>> -> lines },
|
|
//2 to {lines -> lines.filterKeys { it < Month.APRIL }}
|
|
//).k())
|
|
//.let { it }
|
|
//.filterModes(UserMode.OP)
|
|
//.filterMonths(Month.APRIL)
|
|
//.heatMapByHour()
|
|
//.deepMap { it.message }
|
|
.let(::println)
|
|
}
|
|
|
|
// https://arrow-kt.io/docs/recursion/intro/
|
|
|
|
sealed class Node<T> {
|
|
class Leaf<T>(val values: List<T>): Node<T>()
|
|
class Intersection<K, T>(val children: Map<K, Node<T>>): Node<T>()
|
|
|
|
fun <K, R> map(op: (T) -> R): Node<R> {
|
|
return when (this) {
|
|
is Leaf -> Leaf(values.map(op))
|
|
is Intersection<*, *> -> Intersection(children.mapValues { it.value.map<K, R>(op)})
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
private fun <A, K> ListK<A>.grouped(op: (A) -> K): ListK<Tuple2<K, ListK<A>>> {
|
|
return this.groupBy(op).map { it.key toT it.value.k() }.k()
|
|
}
|
|
|
|
private fun <K, A, R> MapK<K, A>.deepMap(AP: Functor<Kind<ForMapK, K>>, op: (A) -> R): Kind<ForMapK, A> {
|
|
val a = AP.run { this@deepMap.mapValues { op(it.value) } }
|
|
}
|
|
*/
|