https://kotlinlang.org logo
Title
a

adjpd

02/13/2022, 9:03 PM
I have a
StateFlow
that I'm collecting from swift. It works with a class that inherits from
Kotlinx_coroutines_coreFlowCollector
. But it's rather ugly. Is there are more concise way? Code in 🧵
class Collector<T> : Kotlinx_coroutines_coreFlowCollector {
    let callback:(T) -> Void

    init(callback: @escaping (T) -> Void) {
        self.callback = callback
    }
    
    func emit(value: Any?) async throws -> KotlinUnit {
        callback(value as! T)
        return KotlinUnit()
    }
}
repo.someStateFlow.collect(
    collector: Collector<TheReturningData> { v in
        print("result \(v)")
    }
) { u, e in
    print("finished")
}
h

hfhbd

02/13/2022, 9:10 PM
j

John O'Reilly

02/13/2022, 9:16 PM
a

adjpd

02/14/2022, 12:04 PM
Thanks, I'll take a look!