Skip to content

Conversation

@xsahil03x
Copy link
Member

@xsahil03x xsahil03x commented Dec 15, 2025

Description of the pull request

Adds an optional compare parameter to the updateWhere list extension. When a Comparator is provided, the list will be sorted after the update operation is applied.

This change also moves updateWhere from ListExtensions to SortedListExtensions to group it with other methods that have sorting capabilities.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a partition method to split lists into two collections based on filter criteria.
    • Introduced optional sorting capability for update operations on sorted collections, enabling automatic reordering after updates.

✏️ Tip: You can customize this high-level summary in your review settings.

Adds an optional `compare` parameter to the `updateWhere` list extension. When a `Comparator` is provided, the list will be sorted after the update operation is applied.

This change also moves `updateWhere` from `ListExtensions` to `SortedListExtensions` to group it with other methods that have sorting capabilities.
@xsahil03x xsahil03x requested a review from a team as a code owner December 15, 2025 16:33
@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 34.70%. Comparing base (5588f40) to head (70ba754).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #24      +/-   ##
==========================================
+ Coverage   34.15%   34.70%   +0.55%     
==========================================
  Files          53       53              
  Lines        1057     1066       +9     
==========================================
+ Hits          361      370       +9     
  Misses        696      696              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Adds a `partition` method to `list_extensions.dart` that splits a list into two lists based on a filter condition, returning a record of `(matching, notMatching)`. Includes comprehensive tests and documentation.
@coderabbitai
Copy link

coderabbitai bot commented Dec 19, 2025

Walkthrough

The changes relocate updateWhere from ListExtensions to SortedListExtensions with an optional compare parameter for post-update sorting, and introduce a new partition method on ListExtensions to split lists by predicate. CHANGELOG documents these upcoming features.

Changes

Cohort / File(s) Summary
Documentation
packages/stream_core/CHANGELOG.md
Added Upcoming section documenting two new features: partition method for list splitting and compare parameter for updateWhere sorting.
Core Implementation
packages/stream_core/lib/src/utils/list_extensions.dart
Removed updateWhere from ListExtensions; added partition method to ListExtensions for splitting lists by predicate; relocated and enhanced updateWhere to SortedListExtensions with optional compare parameter to enable post-update sorting.
Test Suite
packages/stream_core/test/query/list_extensions_test.dart
Added comprehensive tests for partition functionality (empty lists, all/none matches, complex objects) and updateWhere with compare parameter (single/multiple element sorting scenarios); introduced _TestUserWithStatus test model.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–25 minutes

  • Method relocation impact: Verify no existing code depends on updateWhere being available on general List types; ensure SortedListExtensions is the appropriate home for the enhanced version.
  • Optional parameter logic: Review conditional handling of the nullable compare parameter to ensure sorting is applied only when provided and behaves correctly when null.
  • Partition edge cases: Confirm partition implementation handles empty lists and boundary conditions correctly.
  • Test coverage verification: Ensure test scenarios cover both happy paths and edge cases for sorting and partitioning.

Poem

🐰 Thump thump! A partition hops through lists so bright,
Splitting them two ways—left and right!
Updates now compare and sort with grace,
In SortedListExtensions' cozy space.
Lists organized, oh what a sight! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main change: adding optional sorting to updateWhere, which is the primary feature introduced in this PR.
Description check ✅ Passed The description is mostly complete, covering the core change and rationale, though it lacks required CLA checkbox, Linear ticket reference, and testing instructions from the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/sorted-update-where

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5588f40 and 70ba754.

📒 Files selected for processing (3)
  • packages/stream_core/CHANGELOG.md (1 hunks)
  • packages/stream_core/lib/src/utils/list_extensions.dart (1 hunks)
  • packages/stream_core/test/query/list_extensions_test.dart (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: stream_core
🔇 Additional comments (7)
packages/stream_core/CHANGELOG.md (1)

1-7: LGTM!

The changelog clearly documents both new features. The descriptions are concise and accurately reflect the functionality added in this PR.

packages/stream_core/test/query/list_extensions_test.dart (3)

387-427: Excellent test coverage for the sorting functionality!

These tests properly verify that:

  1. The list is sorted after updates when compare is provided
  2. Multiple updated elements are correctly repositioned after sorting
  3. The sort order matches the provided comparator

The test cases are clear and cover both single and multiple element updates.


651-696: Well-structured partition tests!

Good coverage of edge cases including:

  • Empty lists
  • All elements matching
  • No elements matching
  • Complex objects with boolean predicates

The tests verify both that the partition logic works correctly and that the original list remains unchanged (immutability).


2108-2122: LGTM!

The _TestUserWithStatus model is appropriately simple and serves the partition test scenarios well. Using a private class keeps the test scope clean.

packages/stream_core/lib/src/utils/list_extensions.dart (3)

140-189: Excellent implementation of partition!

The method provides a clean, efficient way to split lists in a single pass. The implementation is straightforward and correct:

  • O(n) time complexity as documented
  • Returns an intuitive tuple structure
  • Maintains immutability by creating new lists
  • Documentation includes helpful examples for different use cases

192-197: Good documentation update!

The updated description accurately reflects that this extension now contains methods with both optional and required sorting capabilities, which aligns well with the updated updateWhere method.


199-248: Well-designed enhancement to updateWhere!

Moving this method to SortedListExtensions makes sense organizationally, grouping it with other sorting-capable methods. The implementation is clean and efficient:

  • The optional compare parameter provides flexibility without breaking existing usage patterns
  • Sorting is applied to the entire result when compare is provided, which is the expected behavior
  • Time complexity is correctly documented (O(n) for update, O(n log n) with sorting)
  • The implementation aligns with similar methods like insertUnique and merge that also have optional compare parameters
  • Comprehensive documentation with clear examples of both sorted and unsorted usage

Since both extensions are defined on List<T>, this reorganization doesn't introduce breaking changes for users.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xsahil03x xsahil03x merged commit 62351f6 into main Dec 19, 2025
10 checks passed
@xsahil03x xsahil03x deleted the feat/sorted-update-where branch December 19, 2025 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants