2019-11-26 10:50:38 +01:00
package moe.kageru.spektacles
2019-11-26 16:02:32 +01:00
import arrow.Kind
import arrow.core.*
import arrow.core.extensions.mapk.functor.functor
import arrow.typeclasses.Functor
import moe.kageru.spektacles.Node.Leaf
2019-11-26 13:01:29 +01:00
import java.time.Month
2019-11-26 10:50:38 +01:00
import kotlin.system.measureTimeMillis
fun main ( ) {
2019-11-26 13:01:29 +01:00
val time = measureTimeMillis {
spektacle ( )
2019-11-26 10:50:38 +01:00
}
2019-11-26 13:01:29 +01:00
println ( " Time spent: $time ms " )
2019-11-26 10:50:38 +01:00
}
2019-11-26 13:01:29 +01:00
fun spektacle ( ) {
IoHandler . readFile ( " test.log " )
. parse ( )
2019-11-26 16:02:32 +01:00
. 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 }
2019-11-26 13:01:29 +01:00
. let ( :: println )
2019-11-26 10:50:38 +01:00
}
2019-11-26 16:02:32 +01:00
// 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 ) } }
}
* /