Skip to content

Commit

Permalink
suppress lint warnings for ProduceState since it does always work
Browse files Browse the repository at this point in the history
  • Loading branch information
regulad committed Oct 20, 2024
1 parent 1749dcf commit 9ff4f75
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions compose/src/main/java/xyz/regulad/regulib/compose/flow.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.regulad.regulib.compose

import android.annotation.SuppressLint
import androidx.compose.runtime.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
Expand All @@ -11,6 +12,7 @@ import kotlinx.coroutines.flow.first
* @returns a pair of the state of the collected items and a state of whether the flow has finished. Hot flows will never finish, but the list will be updated as new items are emitted.
*/
@Composable
@SuppressLint("ProduceStateDoesNotAssignValue")
fun <T> Flow<T>.produceState(vararg keys: Any?): Pair<List<T>, Boolean> {
var flowFinished by remember(*keys) { mutableStateOf(false) }

Expand All @@ -33,6 +35,7 @@ fun <T> Flow<T>.produceState(vararg keys: Any?): Pair<List<T>, Boolean> {
* @returns the first item that matches the predicate, and null otherwise
*/
@Composable
@SuppressLint("ProduceStateDoesNotAssignValue")
fun <T> Flow<T>.firstState(vararg keys: Any?, predicate: (T) -> Boolean): T? {
val firstItem by produceState<T?>(null, *keys) {
value = first(predicate)
Expand Down

0 comments on commit 9ff4f75

Please sign in to comment.