Commit 561c366
refactor: simplify lengthBy and lengthBeforeMax using while!
Replace the pattern of:
- one unconditional MoveNextAsync call before the loop
- a mutable 'go' flag
- manual go/step tracking
...with the simpler 'while! e.MoveNextAsync() do' form.
For lengthBy (all three predicate variants), the new implementation is cleaner
and reads more naturally: iterate over elements, count those that match.
For lengthBeforeMax, the new implementation advances the enumerator inside the
loop body and guards with 'go && i < max', eliminating the pre-loop advance.
A beneficial side effect: the old implementation had a read-ahead of 1 (an
extra MoveNextAsync call before the loop), which meant lengthOrMax 5 on a
10-element source would evaluate 6 elements instead of 5, and lengthOrMax 0
would still evaluate the first element. The new implementation has no
read-ahead, so lengthOrMax N evaluates exactly N elements as expected.
Tests updated to reflect the improved (no read-ahead) behaviour, replacing
the N+1 and 1 assertions with the correct N and 0.
All 5013 existing tests pass.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 6fd41af commit 561c366
File tree
3 files changed
+18
-36
lines changed- src
- FSharp.Control.TaskSeq.Test
- FSharp.Control.TaskSeq
3 files changed
+18
-36
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
304 | | - | |
| 303 | + | |
305 | 304 | | |
306 | 305 | | |
307 | 306 | | |
| |||
312 | 311 | | |
313 | 312 | | |
314 | 313 | | |
315 | | - | |
316 | | - | |
| 314 | + | |
| 315 | + | |
317 | 316 | | |
318 | 317 | | |
319 | 318 | | |
320 | | - | |
321 | | - | |
322 | | - | |
| 319 | + | |
323 | 320 | | |
324 | 321 | | |
325 | 322 | | |
| |||
330 | 327 | | |
331 | 328 | | |
332 | 329 | | |
333 | | - | |
334 | | - | |
| 330 | + | |
| 331 | + | |
335 | 332 | | |
336 | 333 | | |
337 | 334 | | |
338 | | - | |
339 | | - | |
340 | | - | |
| 335 | + | |
341 | 336 | | |
342 | 337 | | |
343 | 338 | | |
| |||
349 | 344 | | |
350 | 345 | | |
351 | 346 | | |
352 | | - | |
353 | | - | |
| 347 | + | |
| 348 | + | |
354 | 349 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
183 | 182 | | |
184 | | - | |
185 | 183 | | |
186 | | - | |
187 | | - | |
188 | 184 | | |
189 | 185 | | |
190 | 186 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 187 | + | |
| 188 | + | |
195 | 189 | | |
196 | 190 | | |
197 | | - | |
| 191 | + | |
198 | 192 | | |
199 | 193 | | |
200 | 194 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | 195 | | |
205 | | - | |
| 196 | + | |
206 | 197 | | |
207 | 198 | | |
208 | 199 | | |
209 | 200 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | 201 | | |
214 | 202 | | |
215 | 203 | | |
| |||
219 | 207 | | |
220 | 208 | | |
221 | 209 | | |
222 | | - | |
223 | 210 | | |
224 | | - | |
225 | | - | |
| 211 | + | |
226 | 212 | | |
227 | 213 | | |
228 | | - | |
229 | | - | |
230 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
231 | 217 | | |
232 | 218 | | |
233 | 219 | | |
| |||
0 commit comments