TaskFunctionalInterfaces.kt

@file:JvmName("TaskFunctionalInterfaces")

package com.blizzard.content.filter.chatreplay.sink.task


import com.blizzard.content.filter.chatreplay.domain.ChatLog

import com.blizzard.content.filter.chatreplay.domain.TransformResponse

import kotlinx.coroutines.CoroutineScope

import kotlinx.coroutines.Dispatchers

import kotlinx.coroutines.SupervisorJob


/**

* Functional interfaces defined here, Kotlin-style.

*

* These interfaces give more structure (inheritance, sealed hierarchy) than just typealiases on function declarations.

* They can still be easily declared with a literal function block as a constructor:

*

* ProcessSam { chatLog: ChatLog -> chatLog.toString() }

*

* They can also still be aliased.

*

* https://kotlinlang.org/docs/fun-interfaces.html#functional-interfaces-vs-type-aliases

*/

sealed interface ChatLogTask {

fun taskScope(): CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)

fun timerSpec(): Pair<String, Map<String, String>> = Pair("UndefinedChatLogTask", mapOf())

suspend fun process(chatLog: ChatLog): Any

}


fun interface ProcessTask: ChatLogTask {


override suspend fun process(chatLog: ChatLog): String

}


fun interface PredicateTask: ChatLogTask {


override suspend fun process(chatLog: ChatLog): Boolean

}


fun interface TransformTask: ChatLogTask {


override suspend fun process(chatLog: ChatLog): TransformResponse

}


fun interface ReductionTask: ChatLogTask {


override suspend fun process(chatLog: ChatLog): Long

}