I have the following code ```protected suspend f...
# coroutines
l
I have the following code
Copy code
protected suspend fun stdout(message: String, emit: suspend (WfResult) -> Unit) {
    emit(WfResult.Stdout(message))
}

protected suspend fun stderr(message: String, emit: suspend (WfResult) -> Unit) {
    emit(WfResult.Stderr(message))
}

open fun main() : Flow<Any>  = flow {
   stdout("someString" , ::emit)
 }
How do I make my own flow so I can use it like this (or how do I extend flow to add more methods):
Copy code
open fun main() : Flow<Any>  = myFlow {

   stdout("someString")
   stderr("someString")
 }
a
Make a subinterface of FlowCollector that includes stdout and stderr methods, and then write myFlow to take an extension method on it that delegates to an underlying flow’s emit methods
m
You could also do sth. like this:
Copy code
suspend fun FlowCollector<WfResult>.stderr(message: String) {
    stderr(message, ::emit)
}

suspend fun FlowCollector<WfResult>.stdout(message: String) {
    stdout(message, ::emit)
}
l
thank you, way easier than I thought