Conversation
Adds two new lazy sequence generators that produce elements from a
state value without requiring the element count to be known upfront.
Matches the semantics of Seq.unfold and AsyncSeq.unfold.
- TaskSeq.unfold : synchronous generator ('State -> ('T * 'State) option)
- TaskSeq.unfoldAsync: async generator ('State -> Task<('T * 'State) option>)
Key properties:
- Zero allocations per element beyond the value tuple
- Works lazily: generator is only called as elements are consumed
- Infinite sequences supported (use take/truncate to limit)
- Re-iterating restarts from the original state
14 new tests covering: empty (None immediately), finite sequences,
singleton, Fibonacci via state threading, string generation, infinite
sequence truncation, generator call-count verification, and
re-iteration correctness.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4 tasks
github-actions bot
pushed a commit
that referenced
this pull request
Mar 7, 2026
…289) - TaskSeq.chunkBySize: divides a task sequence into non-overlapping chunks of at most chunkSize elements. Uses a fixed-size array buffer (vs. ResizeArray) to avoid intermediate allocations and resizing. - TaskSeq.windowed: returns overlapping sliding windows of a fixed size. Uses a ring buffer internally so that only a single allocation (per window) is needed; no redundant element copies on each step. Both functions validate their size argument eagerly (before enumeration starts), raise ArgumentException for non-positive sizes, and are fully documented in the .fsi signature file. Also: - Update README.md to mark chunkBySize, windowed, pairwise, scan/scanAsync, reduce/reduceAsync, and unfold/unfoldAsync as implemented (these were merged in PRs #293, #296, #299, #300 respectively). - Update release-notes.txt for 0.5.0. - 171 new tests across TaskSeq.ChunkBySize.Tests.fs and TaskSeq.Windowed.Tests.fs. All 4021 existing tests continue to pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Adds
TaskSeq.unfoldandTaskSeq.unfoldAsync— lazy sequence generators that produce elements from an evolving state value, without requiring the element count to be known upfront. Matches the semantics ofSeq.unfoldandAsyncSeq.unfold.Part of the work to align with
FSharp.Control.AsyncSeq(ref #289). Please do not close #289 as this is one PR of several.Implementation
Motivation
TaskSeq.initandTaskSeq.initAsyncrequire a known count.unfoldfills the gap for cases where the termination condition depends on state (e.g. parsing, pagination, Fibonacci, iterating a cursor).Performance characteristics:
Nonecalltake/truncateto consume infinite-like sequences lazilyChanges
TaskSeqInternal.fstaskSeq {}generators:unfold(sync) andunfoldAsync(async)TaskSeq.fsTaskSeq.unfold/TaskSeq.unfoldAsyncTaskSeq.fsiTaskSeq.Unfold.Tests.fsFSharp.Control.TaskSeq.Test.fsprojAPI
Example
Note on
unfoldAsyncsignatureThe generator is typed as
Task<_>rather than#Task<_>(flexible type) because thetaskSeq {}builder requires a type annotation to resolve theBindoverload. In practice, callers usingtask { return ... }expressions will satisfy this constraint directly.Test Status
Build: ✅ succeeded (0 warnings, 0 errors)
Tests: ✅ 14/14 passed
Fantomas: ✅ clean after formatting
Test cases:
take 100