collect
fun collect(onEach: (T) -> Unit, onComplete: () -> Unit? = null, onError: (Throwable) -> Unit? = null)
Starts collecting the flow and calls onEach for every emitted value. Call cancel to stop collecting.
Parameters
onEach
Called for each emitted value.
onComplete
Called when the flow completes (optional).
onError
Called if the flow throws an error (optional).