wip
This commit is contained in:
parent
f2a1a74bb8
commit
fa66c1ddcf
|
@ -1,5 +1,7 @@
|
|||
package moe.kageru.spektacles
|
||||
|
||||
import arrow.Kind
|
||||
import arrow.typeclasses.Functor
|
||||
import java.time.Month
|
||||
|
||||
fun ParsedLines.heatMapByHour(): SortedCounter<Int> = heatMapBy { it.time.hour }
|
||||
|
@ -13,3 +15,6 @@ private fun <T: Comparable<T>>ParsedLines.heatMapBy(op: (ParsedLine) -> T): Sort
|
|||
.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) } }
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
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
|
||||
|
||||
|
@ -13,9 +18,42 @@ fun main() {
|
|||
fun spektacle() {
|
||||
IoHandler.readFile("test.log")
|
||||
.parse()
|
||||
.filterUsers("kageru_")
|
||||
.filterModes(UserMode.OP)
|
||||
.filterMonths(Month.APRIL)
|
||||
.heatMapByHour()
|
||||
.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) } }
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user