flow from the given suspendable block • flowOf() -> defines a flow emitting a fixed set of values • .asFlow() -> extension function for collections and sequences
the results of applying the given transform function to each value of the original flow • filter{} -> returns a flow containing only values of the original flow that matches the given predicate • transform{} -> it can be used to imitate simple transformations as well more complex transformations. We can emit arbitrary values an arbitrary number of times • take() -> cancel the execution of the flow when the corresponding limit is reached
with a provided action. If any exception occurs during collect or in the provided flow, this exception is rethrown from this method • reduce{} -> accumulates value starting with the first element and applying operation to current accumulator value and each element. Throws NoSuchElementException if flow was empty • fold{} -> accumulates value starting with initial value and applying operation current accumulator value and each element They are suspending functions that start a collection of the flow
emitted by the flow and then cancels flow's collection. Throws NoSuchElementException if the flow was empty • single{} -> awaits for one and only one value to be published. Throws NoSuchElementException for empty flow and IllegalStateException for flow that contains more than one element They are suspending functions that start a collection of the flow
the calling coroutine • You can’t change manually the context under a collection is being executed • Using of flowOn function is the only to change the context of the flow emission
could be an issue when both the emitter and the collector take too long to processing each element • Remember that usually the flows run under the same context into the same coroutine • Can we decouple the emitter and the collector without changing the code?
the emitter in a separate coroutine from the collector would do both concurrent • With two separate coroutines we need to establish some communication between both of them • Here is where Channels enter to scene providing a mechanism where we can send the elements from the emitter and receive them in another one, through a channel.
specified capacity and runs collector in a separate coroutine. Normally, flows are sequential. It means that the code of all operators is executed in the same coroutine. • The buffer operator creates a separate coroutine during execution for the flow it applies to.
the original flow by applying transform, that returns another flow, and then concatenating and flattening these flows • flatMapMerge { } - transforms elements emitted by the original flow by applying transform, that returns another flow, and then merging and flattening these flows. • flatMapLatest {} - returns a flow that switches to a new flow produced by transform function every time the original flow emits a value. When the original flow emits a new value, the previous flow produced by transform block is cancelled.
of two flows • combine() - when flow represents the most recent value of a variable or operation, it might be needed to perform a computation that depends on the most recent values of the corresponding flows and to recompute it whenever any of the upstream flows emit a value
Exceptions can be turned into emission of values using emit from the body of catch. • Exceptions can be ignored, logged, or processed by some other code.
Flow https://medium.com/makingtuenti/asynchronous-development-in-android-rxja va-vs-kotlin-flow-f7fdf2e2f81b • From RxJava 2 to Kotlin Flow: Threading https://proandroiddev.com/from-rxjava-2-to-kotlin-flow-threading-8618867e1 955 • The Real Kotlin Flow benefits over RxJava https://proandroiddev.com/the-real-kotlin-flow-benefits-over-rxjava-c19b99ba 6eb9