-
public final class FlowKt
-
-
Method Summary
Modifier and Type Method Description final static <T extends Any> UnitcollectWith(Flow<T> $self, CoroutineScope scope, Function1<T, Unit> block)Utility for removing some of the boilerplate around Synchronizers and working with flows. final static <T extends Any, S extends Any> UnitonFirstWith(Flow<T> $self, CoroutineScope scope, SuspendFunction1<T, S> block)Utility for performing the given action on the first emission of a flow and running that action in the given scope. final static <T extends Any, S extends Any> UnitonFirst(Flow<T> $self, SuspendFunction1<T, S> block)Utility for performing the given action on the first emission of a flow. -
-
Method Detail
-
collectWith
final static <T extends Any> Unit collectWith(Flow<T> $self, CoroutineScope scope, Function1<T, Unit> block)
Utility for removing some of the boilerplate around Synchronizers and working with flows. Allows for collecting all the elements of a flow with a given scope this is useful when you want to launch multiple things in the same scope at once. Intuitively a developer may try:
scope.launch { flow1.collect { collectingFunction1() } flow2.collect { collectingFunction2() } }But this results in the collections running sequentially rather than in parallel. Alternatively, This code produces the desired behavior but is verbose and a little unclear:
scope.launch { flow1.collect { collectingFunction1() } } scope.launch { flow1.collect { collectingFunction2() } }This extension functions makes the intended behavior a little easier to read by focusing on the flow itself rather than the scope:
flow1.collectWith(scope, ::collectingFunction1) flow2.collectWith(scope, ::collectingFunction2)
-
onFirstWith
final static <T extends Any, S extends Any> Unit onFirstWith(Flow<T> $self, CoroutineScope scope, SuspendFunction1<T, S> block)
Utility for performing the given action on the first emission of a flow and running that action in the given scope.
Unused in the SDK but is used by the wallet app
-
onFirst
final static <T extends Any, S extends Any> Unit onFirst(Flow<T> $self, SuspendFunction1<T, S> block)
Utility for performing the given action on the first emission of a flow.
-
-
-
-