Skip to content

4.x: Add Streamable count operator - #8396

Merged
akarnokd merged 1 commit into
ReactiveX:4.xfrom
jimi-21:feat/streamable-count
Nov 17, 2026
Merged

akarnokd merged 1 commit into
ReactiveX:4.xfrom
jimi-21:feat/streamable-count

Conversation

@jimi-21

@jimi-21 jimi-21 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Related #8299.

Summary

Add Streamable.count() with Single<Long> as its result type.

The implementation composes the existing collect(Collectors.counting()) and lastOrError() operators. It returns 0 for an empty source, counts all items otherwise, and propagates upstream errors.

Internal record compatibility

Adding this method makes five existing record component accessors incompatible with Streamable.count(): StreamableRange, StreamableRangeLong, StreamableIntervalRange, StreamableSkip, and StreamableTake each had a count component whose generated accessor returned int or long.

Their top-level record components are renamed to itemCount. Constructor parameter types and order, stream calculations, and nested streamer fields are unchanged.

Tests

Added StreamableCountTest for empty sources, multiple items, and upstream error propagation.

Test-first evidence: before adding count(), the new test class failed compilation with three missing-method errors. The first implementation then exposed the five record-accessor return-type conflicts described above; the internal component renames resolve them without changing constructor signatures.

The following focused tests pass on Zulu JDK 26:

  • StreamableCountTest
  • StreamableJustTest
  • StreamableRangeTest
  • StreamableIntervalRangeTest
  • StreamableSkipTest
  • StreamableTakeTest
  • CheckParamValidationNamingTest.checkStreamable

Total: 91 tests, 0 failures/errors, 6 existing skips. checkstyleMain and checkstyleTest also pass. The full suite was not run for this separate focused addition.

AI disclosure: Kimi Code assisted with API analysis, implementation, record-conflict analysis, tests, local verification, and this PR description. The failing-before compilation results, final affected tests, and seven-file diff were checked.

CI result for a19acc4

All checks pass: Validation, default build, JDK 27, JDK 28, the security scan, codecov/patch, and codecov/project.

@github-actions

Copy link
Copy Markdown

🐷 TruffleHog + Entropy Beauty Scan

Average entropy of changed code: 4.56 bits/char
Verdict: ✅ Mid-4 beauty detected (thoughtful human code!)

Changed files entropy:

src/main/java/io/reactivex/rxjava4/core/Streamable.java: 4.648
src/main/java/io/reactivex/rxjava4/internal/operators/streamable/StreamableIntervalRange.java: 4.365
src/main/java/io/reactivex/rxjava4/internal/operators/streamable/StreamableRange.java: 4.559
src/main/java/io/reactivex/rxjava4/internal/operators/streamable/StreamableRangeLong.java: 4.579
src/main/java/io/reactivex/rxjava4/internal/operators/streamable/StreamableSkip.java: 4.367
src/main/java/io/reactivex/rxjava4/internal/operators/streamable/StreamableTake.java: 4.565
src/test/java/io/reactivex/rxjava4/internal/operators/streamable/StreamableCountTest.java: 4.836

✅ No secrets or suspicious high-entropy strings found.

Mid-4 beauty heuristic in action — powered by our entropy chats! 😊

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.63%. Comparing base (a6f2d16) to head (a19acc4).

Additional details and impacted files
@@             Coverage Diff              @@
##                4.x    #8396      +/-   ##
============================================
+ Coverage     98.58%   98.63%   +0.04%     
- Complexity     7169     7170       +1     
============================================
  Files           826      826              
  Lines         50972    50973       +1     
  Branches       6944     6944              
============================================
+ Hits          50251    50275      +24     
+ Misses          482      474       -8     
+ Partials        239      224      -15     

☔ View full report in Codecov by Harness.
📢 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.

@akarnokd
akarnokd merged commit dea167e into ReactiveX:4.x Nov 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants