Skip to content

Make Flow.range support descending ranges with negative step#455

Merged
adamw merged 3 commits into
masterfrom
fix-flow-range-negative-step
Jun 8, 2026
Merged

Make Flow.range support descending ranges with negative step#455
adamw merged 3 commits into
masterfrom
fix-flow-range-negative-step

Conversation

@adamw

@adamw adamw commented Jun 7, 2026

Copy link
Copy Markdown
Member

Fixes #439 — Flow.range with a negative step was only emitting the first element due to incorrect termination logic.

The original implementation used a fixed termination condition (t <= to) that didn't account for negative steps. With a negative step, this condition would cause the loop to terminate prematurely.

The fix updates the range method to:

  • Require non-zero step values
  • Use conditional termination logic: t <= to for positive steps, t >= to for negative steps
  • Document the descending range behavior with examples

Test cases for descending ranges have been added to verify the fix works correctly.

Closes #439.

@adamw

adamw commented Jun 7, 2026

Copy link
Copy Markdown
Member Author

The failure is clear. Here's the summary:


CI failure: Flow.range negative step not yet implemented

Both ci (21) and ci (24) fail on the same test in FlowOpsFactoryMethodsTest:

- should produce a descending range with a negative step *** FAILED ***
  List(5) was not equal to List(5, 4, 3, 2, 1) (FlowOpsFactoryMethodsTest.scala:30)

Flow.range(5, 0, -1) (or equivalent) currently returns only List(5) instead of List(5, 4, 3, 2, 1). The termination condition in Flow.range does not account for a negative step — it stops immediately after the first element because it checks current < end (or similar ascending-only guard) even when stepping downward.

@adamw adamw changed the title Fix Flow.range to handle negative steps Make Flow.range support descending ranges with negative step Jun 7, 2026
@adamw adamw merged commit d22c3a3 into master Jun 8, 2026
6 checks passed
@adamw adamw deleted the fix-flow-range-negative-step branch June 8, 2026 08:41
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.

Flow.range with a negative step emits only the first element

1 participant