Skip to content

Add NewLimitIterator to cap iterator output to N items#1555

Open
simonfaltum wants to merge 2 commits intomainfrom
simonfaltum/limit-iterator
Open

Add NewLimitIterator to cap iterator output to N items#1555
simonfaltum wants to merge 2 commits intomainfrom
simonfaltum/limit-iterator

Conversation

@simonfaltum
Copy link
Member

Summary

  • Adds NewLimitIterator[T](iter, n) to listing package: a lazy iterator wrapper that yields at most N items
  • Follows the existing DeduplicatingIterator pattern (unexported struct, exported constructor returning Iterator[T])
  • n <= 0 means no limit (returns inner iterator unchanged)

Motivation

The Databricks CLI needs to limit output from paginated list commands (--limit flag). ToSliceN exists for the slice case, but there's no lazy equivalent for streaming iteration. This fills that gap.

Tests

8 new subtests covering: limit below/above total, limit of one, zero/negative as no-op, exhaustion via Next, error propagation, standard HasNext/Next loop.

Co-authored-by: Isaac
Signed-off-by: simon <simon.faltum@databricks.com>
- Add NEXT_CHANGELOG.md entry for NewLimitIterator
- Document divergence from ToSliceN for negative inputs in doc comment
- Add HasNext idempotency subtest

Co-authored-by: Isaac
Signed-off-by: simon <simon.faltum@databricks.com>
@github-actions
Copy link

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-go

Inputs:

  • PR number: 1555
  • Commit SHA: 30dd23c01acfd6d85c64b5b29680c8ec382f3b18

Checks will be approved automatically on success.

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.

1 participant