Skip to content

Commit

Permalink
Consider empty list when combining.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynewstrom-stripe committed May 6, 2024
1 parent 0180c95 commit 85bc434
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.stripe.android.uicore.elements
import androidx.annotation.RestrictTo
import androidx.annotation.StringRes
import com.stripe.android.uicore.utils.combineAsStateFlow
import com.stripe.android.uicore.utils.stateFlowOf
import kotlinx.coroutines.flow.StateFlow

/**
Expand All @@ -13,11 +14,15 @@ class SectionController(
@StringRes val label: Int?,
sectionFieldErrorControllers: List<SectionFieldErrorController>
) : Controller {
val error: StateFlow<FieldError?> = combineAsStateFlow(
sectionFieldErrorControllers.map {
it.error
val error: StateFlow<FieldError?> = if (sectionFieldErrorControllers.isEmpty()) {
stateFlowOf(null)
} else {
combineAsStateFlow(
sectionFieldErrorControllers.map {
it.error
}
) { errorArray ->
errorArray.firstNotNullOfOrNull { it }
}
) { errorArray ->
errorArray.firstNotNullOfOrNull { it }
}
}

0 comments on commit 85bc434

Please sign in to comment.