You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is request to add Flow.onEmpty and/or Flow.ifEmpty operators that would enable concise check for check for empty flows, example:
flow.onEmpty { error("Must have an element") } // error on empty flow
flow.onEmpty { emit(default) } // default value on empty flow
flow.ifEmpty { default } // same as above
I have a multiplatform library that's being shared internally at my company. We've exposed an API purposely that it can't emit any errors. At a lower level in the library we create a Flow, and emit the cached value (if there is one), and the server value (if it succeeds). This lower level of the library doesn't have access to the default value that is provided by the user. It's far easier to provide a default value at the higher level, which is what this operator would be used for. It's important that we always output at least one value.
There is request to add
Flow.onEmpty
and/orFlow.ifEmpty
operators that would enable concise check for check for empty flows, example:Original request: https://kotlinlang.slack.com/archives/C1CFAFJSK/p1585630443171500
The text was updated successfully, but these errors were encountered: