'Combine Kotlin Unit flows without transform function

I have currently two SharedFlows that I need to combine to do something, but I don't really need the result from the transformation function, I only want to know if both "events" started yet. While implementing this I get this useless bracket body:

combine(
  flow1, // SharedFlow<Unit>
  flow2, // SharedFlow<Unit>
) { _, _ ->

  // Useless function body

}.onEach {
  // Do some work
}.launchIn(scope)

Is there a way I can do this more cleanly without the need for the transform function?



Solution 1:[1]

You can "Do some work" in "Useless function body" instead of onEach:

combine(
  flow1, // SharedFlow<Unit>
  flow2, // SharedFlow<Unit>
) { _, _ ->

  // Do some work

}.launchIn(scope)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BigSt