Skip to content

feat(Itertools): add strip_prefix and strip_prefix_by methods#1104

Open
SAY-5 wants to merge 1 commit into
rust-itertools:masterfrom
SAY-5:feat/strip-prefix
Open

feat(Itertools): add strip_prefix and strip_prefix_by methods#1104
SAY-5 wants to merge 1 commit into
rust-itertools:masterfrom
SAY-5:feat/strip-prefix

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 18, 2026

Adds strip_prefix and strip_prefix_by to the Itertools trait, the iterator analogue of str::strip_prefix, as discussed in #1096. strip_prefix is implemented in terms of strip_prefix_by, which takes an equality predicate so the prefix items may differ in type from Self::Item. Includes doctests and quickcheck tests that assert parity with str::strip_prefix.

Closes #1096

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.03%. Comparing base (6814180) to head (7a655bf).
⚠️ Report is 202 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1104      +/-   ##
==========================================
- Coverage   94.38%   94.03%   -0.36%     
==========================================
  Files          48       51       +3     
  Lines        6665     6657       -8     
==========================================
- Hits         6291     6260      -31     
- Misses        374      397      +23     

☔ 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.

@phimuemue
Copy link
Copy Markdown
Member

phimuemue commented May 19, 2026

Hi there, thanks for this.

Regarding the API: Currently this only returns Some(self_after_prefix_removal) on success, but the failure case may be equally interesting for callers.

Can we - instead of Option<Self> - return a Result<Self, (Self, Self::Item, J::Item, J)>, where the Ok case resembles the prefix-removed iterator, and the Err case holds all cheaply-obtainable components that may be of interest for the caller?

  • prefix-partially-removed iterator (Self)
  • mismatched items (Self::Item vs J::Item)
  • remaining prefix (J)

Returning a bespoke struct for the error case may be viable, too.

@SAY-5
Copy link
Copy Markdown
Author

SAY-5 commented May 19, 2026

Makes sense, the failure case is worth exposing. I'll switch the return type to Result<Self, (Self, Self::Item, J::Item, J)> so callers can recover the partially-consumed iterators and the mismatched items. Will push the reworked version shortly.

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.

Itertools::strip_prefix

2 participants