Skip to content

Conversation

@hoc081098
Copy link
Owner

Status

READY/IN DEVELOPMENT/HOLD

Breaking Changes

YES | NO

Description

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

Requirements

  • Dump api
  • Update README
  • Update CHANGELOG
  • Add tests
  • Add docs

@hoc081098 hoc081098 added the enhancement New feature or request label Dec 8, 2024
@hoc081098 hoc081098 self-assigned this Dec 8, 2024
@codecov
Copy link

codecov bot commented Dec 8, 2024

Codecov Report

Attention: Patch coverage is 6.52174% with 129 lines in your changes missing coverage. Please review.

Project coverage is 76.35%. Comparing base (62e1c05) to head (3ebb41e).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...monMain/kotlin/com/hoc081098/flowext/StateFlows.kt 6.52% 129 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@hoc081098 hoc081098 requested a review from Copilot August 30, 2025 14:19
Copy link

Copilot AI left a 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(
Copy link

Copilot AI Aug 30, 2025

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..'

Copilot uses AI. Check for mistakes.
* @see mapState
*/
@FlowExtPreview
public fun <T1, T2, T3, R> combineStates(
Copy link

Copilot AI Aug 30, 2025

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..'

Copilot uses AI. Check for mistakes.
* @see mapState
*/
@FlowExtPreview
public fun <T1, T2, T3, T4, R> combineStates(
Copy link

Copilot AI Aug 30, 2025

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..'

Copilot uses AI. Check for mistakes.
* @see mapState
*/
@FlowExtPreview
public fun <T1, T2, T3, T4, T5, R> combineStates(
Copy link

Copilot AI Aug 30, 2025

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..'

Copilot uses AI. Check for mistakes.
* @see mapState
*/
@FlowExtPreview
public fun <T1, T2, T3, T4, T5, T6, R> combineStates(
Copy link

Copilot AI Aug 30, 2025

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..'

Copilot uses AI. Check for mistakes.
* @see mapState
*/
@FlowExtPreview
public fun <T1, T2, T3, T4, T5, T6, T7, T8, R> combineStates(
Copy link

Copilot AI Aug 30, 2025

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..'

Copilot uses AI. Check for mistakes.
* @see mapState
*/
@FlowExtPreview
public fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> combineStates(
Copy link

Copilot AI Aug 30, 2025

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..'

Copilot uses AI. Check for mistakes.
* @see mapState
*/
@FlowExtPreview
public fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R> combineStates(
Copy link

Copilot AI Aug 30, 2025

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..'

Copilot uses AI. Check for mistakes.
* @see mapState
*/
@FlowExtPreview
public fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R> combineStates(
Copy link

Copilot AI Aug 30, 2025

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..'

Copilot uses AI. Check for mistakes.
* @see mapState
*/
@FlowExtPreview
public fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R> combineStates(
Copy link

Copilot AI Aug 30, 2025

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..'

Copilot uses AI. Check for mistakes.
@hoc081098
Copy link
Owner Author

@codex review code

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

Comment on lines +63 to +72
@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) },
)

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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants