Skip to content

[code-simplifier] Remove redundant boolean guards in ZipNObservable.onNext#2042

Merged
alexandru merged 2 commits into
mainfrom
code-simplifier/remove-redundant-boolean-guards-zip-observables-6c11a7b16633d0d2
Apr 28, 2026
Merged

[code-simplifier] Remove redundant boolean guards in ZipNObservable.onNext#2042
alexandru merged 2 commits into
mainfrom
code-simplifier/remove-redundant-boolean-guards-zip-observables-6c11a7b16633d0d2

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Simplification of recently merged code from #2040 ("Fix zip observable to upstream (v2)").

Files Simplified

  • Zip2Observable.scala — removed 2 redundant guards
  • Zip3Observable.scala — removed 3 redundant guards
  • Zip4Observable.scala — removed 4 redundant guards
  • Zip5Observable.scala — removed 5 redundant guards
  • Zip6Observable.scala — removed 6 redundant guards

Improvement Made

In each subscriber's onNext handler, the following pattern appeared for every source element variable:

elemAX = elem
if (!hasElemAX) hasElemAX = true

Setting a Boolean variable to true when it is already true is a no-op, so the if guard is redundant. The simplified form is:

elemAX = elem
hasElemAX = true

This removes dead branching logic and makes the intent clearer — upon receiving an element, we unconditionally record that we have it.

Changes Based On

Testing

This is a pure simplification: no logic changes. The hasElemAX variables are only ever set to true in onNext and reset to false in rawOnNext (after emitting a combined element). The guard if (!hasElemAX) was never observable in behavior since writing true over true is idempotent.

References: §25036401375

Generated by Code Simplifier · ● 799.7K ·

To install this agentic workflow, run

gh aw add github/gh-aw/.github/workflows/code-simplifier.md@852cb06ad52958b402ed982b69957ffc57ca0619
  • expires on Apr 29, 2026, 5:58 AM UTC

In each subscriber's onNext handler, the pattern:

was guarding a no-op. Setting a boolean to true when it's already
true is idempotent, so the guard is unnecessary. Simplify to:
  hasElemAX = true

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@alexandru alexandru marked this pull request as ready for review April 28, 2026 08:53
@alexandru alexandru enabled auto-merge (squash) April 28, 2026 13:54
@alexandru alexandru merged commit 0fda836 into main Apr 28, 2026
13 checks passed
@alexandru alexandru deleted the code-simplifier/remove-redundant-boolean-guards-zip-observables-6c11a7b16633d0d2 branch April 28, 2026 13:58
@github-actions github-actions Bot mentioned this pull request Apr 29, 2026
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.

1 participant