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, Node>(::Leaf) //.grouped { it.time.year } //.mapValues { it.value.groupBy { it.time.month } }.k() //.ap(mapOf( //1 to { lines: Map> -> 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 { class Leaf(val values: List): Node() class Intersection(val children: Map>): Node() fun map(op: (T) -> R): Node { return when (this) { is Leaf -> Leaf(values.map(op)) is Intersection<*, *> -> Intersection(children.mapValues { it.value.map(op)}) } } } /* private fun ListK.grouped(op: (A) -> K): ListK>> { return this.groupBy(op).map { it.key toT it.value.k() }.k() } private fun MapK.deepMap(AP: Functor>, op: (A) -> R): Kind { val a = AP.run { this@deepMap.mapValues { op(it.value) } } } */