Hi, I'm trying to integrate IO with the <#CJF76ENE...
# arrow
k
Hi, I'm trying to integrate IO with the #uniflow library, but I'm at a loss on how to tackle it… Uniflow already supports coroutines so it (supposedly) should be a breeze 😄 Heres how the syntax look like for coroutines (taken from uniflow github) :
Copy code
fun childIO() = setState { // -> See <https://github.com/uniflow-kt/uniflow-kt/blob/master/uniflow-core/src/main/kotlin/io/uniflow/core/flow/DataFlow.kt#L93>
    onIO {  // -> coroutine's IO : suspend fun <T> onIO(block: suspend CoroutineScope.() -> T) = withContext(<http://UniFlowDispatcher.dispatcher.io|UniFlowDispatcher.dispatcher.io>(), block = block)
        delay(100)
        repository.add("LongTodo")
        repository.getAllTodo().mapToTodoListState() // -> fun getAllTodo() : List<Todo>
                                                     // -> fun List<Todo>.mapToTodoListState() : TodoListState
    }
}
What I'm trying to have is a similar syntax to this, with a
setState
taking
IO
instead of suspending functions:
Copy code
fun getAllTodo(): IO<List<Todo>>
fun childIO() = setState { getAllTodo().map { TodoListState(it) } }
Any idea where I should start? I've seen that @Jorge Castillo commented on arrow issues in the uniflow github, maybe he'll know what I'm talking about ^^
a
Hi @kluck! I’m not familiar with the syntax of uniflow, but I think you might be able to make it work if you convert your IOs to a suspend function by calling
suspended()/suspendCancellable()
on it, so you would have
suspended fun getAllTodo(): List<Todo>
k
@aballano That did the trick, thank you!
🙌 2