Commit ab07918
refactor: fix traverseOptionAsync/traverseChoiceAsync — avoid wasteful MoveNext on failure
Both functions previously called ie.MoveNext() unconditionally at the end
of each loop iteration. When the mapping function f returned failure
(None / Choice2Of2), the loop set the sentinel variables and then still
called MoveNext(), reading one element from the source that would never
be used. For sequences with observable side effects on enumeration this
was unexpected behaviour.
Fix: restructure the loop so MoveNext() is only called in the success
branch. Also modernise mutable state from ref cells to mutable locals.
Tests: 4 new tests covering
- success path for both functions (returns all mapped values)
- 'does not read past failing element' assertion (enumerator read count)
All 325 tests pass.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 3249128 commit ab07918
File tree
2 files changed
+82
-31
lines changed- src/FSharp.Control.AsyncSeq
- tests/FSharp.Control.AsyncSeq.Tests
2 files changed
+82
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2332 | 2332 | | |
2333 | 2333 | | |
2334 | 2334 | | |
2335 | | - | |
2336 | | - | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
2337 | 2338 | | |
2338 | | - | |
2339 | | - | |
2340 | | - | |
2341 | | - | |
2342 | | - | |
2343 | | - | |
2344 | | - | |
2345 | | - | |
2346 | | - | |
2347 | | - | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
2348 | 2350 | | |
2349 | | - | |
2350 | | - | |
2351 | | - | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
2352 | 2354 | | |
2353 | 2355 | | |
2354 | 2356 | | |
2355 | | - | |
2356 | | - | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
2357 | 2360 | | |
2358 | | - | |
2359 | | - | |
2360 | | - | |
2361 | | - | |
2362 | | - | |
2363 | | - | |
2364 | | - | |
2365 | | - | |
2366 | | - | |
2367 | | - | |
2368 | | - | |
2369 | | - | |
2370 | | - | |
2371 | | - | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
2372 | 2376 | | |
2373 | 2377 | | |
2374 | 2378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1211 | 1211 | | |
1212 | 1212 | | |
1213 | 1213 | | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
1214 | 1261 | | |
1215 | 1262 | | |
1216 | 1263 | | |
| |||
0 commit comments