--

Instead of using stateIn() in the collect() method which creates an unnecessary StateFlow instance with a single collector, you could just collect the combined Flow then throw an illegal state exception right after, ensuring the method will never return.
Since the source flows are all StateFlows then collect will never return and the exception will not be thrown but the return type will be Nothing.

--

--

Christophe Beyls
Christophe Beyls

Written by Christophe Beyls

Android developer from Belgium, blogging about advanced programming topics.

No responses yet