Skip to content

Comments

Add flat_map_ok iterator adaptor#1087

Open
veeceey wants to merge 1 commit intorust-itertools:masterfrom
veeceey:feat/issue-528-flat-map-ok
Open

Add flat_map_ok iterator adaptor#1087
veeceey wants to merge 1 commit intorust-itertools:masterfrom
veeceey:feat/issue-528-flat-map-ok

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 23, 2026

Adds a flat_map_ok adaptor that applies a function to Ok values and flattens the result, passing Err values through unchanged. Basically a combined .map_ok(f).flatten_ok() in a single step.

The implementation follows the same pattern as the existing flatten_ok adaptor, with support for:

  • DoubleEndedIterator (when the inner iterator supports it)
  • FusedIterator
  • Clone / Debug
  • fold / rfold optimizations

Example usage:

let input = vec![Ok(2i32), Err(false), Ok(3i32)];
let it = input.into_iter().flat_map_ok(|i| 0..i);
// yields: Ok(0), Ok(1), Err(false), Ok(0), Ok(1), Ok(2)

Closes #528

Implements flat_map_ok, which applies a function to Ok(T) values and
flattens the resulting iterator, passing Err values through unchanged.

Equivalent to .map_ok(f).flatten_ok() but avoids the intermediate
iterator type. Supports DoubleEndedIterator, FusedIterator, Clone,
Debug, fold/rfold optimizations.

Closes rust-itertools#528
@veeceey
Copy link
Author

veeceey commented Feb 23, 2026

Test results:

running 8 tests
test flat_map_ok_all_errors ... ok
test flat_map_ok_collect_ok_reverse ... ok
test flat_map_ok_collect_ok_forward ... ok
test flat_map_ok_collect_mixed ... ok
test flat_map_ok_empty_results ... ok
test flat_map_ok_equivalence_with_map_ok_flatten_ok ... ok
test flat_map_ok_mixed_forward ... ok
test flat_map_ok_mixed_reverse ... ok

test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Full test suite also passes (202 tests).

@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 61.53846% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.25%. Comparing base (6814180) to head (d092fd7).
⚠️ Report is 178 commits behind head on master.

Files with missing lines Patch % Lines
src/flat_map_ok.rs 56.98% 40 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1087      +/-   ##
==========================================
- Coverage   94.38%   93.25%   -1.14%     
==========================================
  Files          48       52       +4     
  Lines        6665     6571      -94     
==========================================
- Hits         6291     6128     -163     
- Misses        374      443      +69     

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

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.

flat_map_ok

1 participant