-
-
Notifications
You must be signed in to change notification settings - Fork 27
add StateFlow<T>.mapState, combineStates(StateFlow<T>...)
#317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #317 +/- ##
===========================================
- Coverage 88.38% 76.35% -12.04%
===========================================
Files 37 38 +1
Lines 801 939 +138
Branches 107 107
===========================================
+ Hits 708 717 +9
- Misses 52 181 +129
Partials 41 41 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds new StateFlow utility functions to the FlowExt library, providing convenient methods for mapping and combining StateFlow instances while preserving their state characteristics.
- Adds
StateFlow<T>.mapState()extension function for transforming StateFlow values - Adds
combineStates()functions with 2-12 parameter overloads for combining multiple StateFlows - Includes comprehensive test coverage and API documentation
Reviewed Changes
Copilot reviewed 5 out of 8 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| src/commonMain/kotlin/com/hoc081098/flowext/StateFlows.kt | New file implementing mapState and combineStates functions with internal StateFlow implementations |
| src/commonTest/kotlin/com/hoc081098/flowext/MapStateTest.kt | Test file covering mapState functionality and readonly state flow validation |
| src/commonTest/kotlin/com/hoc081098/flowext/utils/BaseTest.kt | Added helper function for validating readonly StateFlow instances |
| api/FlowExt.api | Updated API dump reflecting new public functions |
| api/FlowExt.klib.api | Updated Kotlin library API dump |
Files not reviewed (2)
- .idea/misc.xml: Language not supported
- .idea/vcs.xml: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| * @see mapState | ||
| */ | ||
| @FlowExtPreview | ||
| public fun <T1, T2, R> combineStates( |
Copilot
AI
Aug 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra period at the end of the documentation comment. Remove the double period in 'transform function..'
| * @see mapState | ||
| */ | ||
| @FlowExtPreview | ||
| public fun <T1, T2, T3, R> combineStates( |
Copilot
AI
Aug 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra period at the end of the documentation comment. Remove the double period in 'transform function..'
| * @see mapState | ||
| */ | ||
| @FlowExtPreview | ||
| public fun <T1, T2, T3, T4, R> combineStates( |
Copilot
AI
Aug 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra period at the end of the documentation comment. Remove the double period in 'transform function..'
| * @see mapState | ||
| */ | ||
| @FlowExtPreview | ||
| public fun <T1, T2, T3, T4, T5, R> combineStates( |
Copilot
AI
Aug 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra period at the end of the documentation comment. Remove the double period in 'transform function..'
| * @see mapState | ||
| */ | ||
| @FlowExtPreview | ||
| public fun <T1, T2, T3, T4, T5, T6, R> combineStates( |
Copilot
AI
Aug 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra period at the end of the documentation comment. Remove the double period in 'transform function..'
| * @see mapState | ||
| */ | ||
| @FlowExtPreview | ||
| public fun <T1, T2, T3, T4, T5, T6, T7, T8, R> combineStates( |
Copilot
AI
Aug 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra period at the end of the documentation comment. Remove the double period in 'transform function..'
| * @see mapState | ||
| */ | ||
| @FlowExtPreview | ||
| public fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> combineStates( |
Copilot
AI
Aug 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra period at the end of the documentation comment. Remove the double period in 'transform function..'
| * @see mapState | ||
| */ | ||
| @FlowExtPreview | ||
| public fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R> combineStates( |
Copilot
AI
Aug 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra period at the end of the documentation comment. Remove the double period in 'transform function..'
| * @see mapState | ||
| */ | ||
| @FlowExtPreview | ||
| public fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R> combineStates( |
Copilot
AI
Aug 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra period at the end of the documentation comment. Remove the double period in 'transform function..'
| * @see mapState | ||
| */ | ||
| @FlowExtPreview | ||
| public fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R> combineStates( |
Copilot
AI
Aug 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra period at the end of the documentation comment. Remove the double period in 'transform function..'
|
@codex review code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
| @FlowExtPreview | ||
| public fun <T1, T2, R> combineStates( | ||
| flow1: StateFlow<T1>, | ||
| flow2: StateFlow<T2>, | ||
| transform: (T1, T2) -> R, | ||
| ): StateFlow<R> = | ||
| DerivedStateFlow( | ||
| source = combine(flow1, flow2, transform), | ||
| valueSupplier = { transform(flow1.value, flow2.value) }, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Avoid emitting unchanged values in combineStates
mapState applies distinctUntilChanged() so derived state only notifies observers when the mapped value actually changes, but all combineStates overloads feed combine(...) directly into DerivedStateFlow without a deduplication step. When inputs change but transform evaluates to the same result (e.g., combining two StateFlow<Boolean> with || while each flow toggles), collectors will receive identical values repeatedly, causing unnecessary downstream work and breaking the typical StateFlow expectation that equal values are suppressed. Consider applying distinctUntilChanged() after combine(...) so only meaningful state changes propagate.
Useful? React with 👍 / 👎.
Status
READY/IN DEVELOPMENT/HOLD
Breaking Changes
YES | NO
Description
Type of Change
Requirements