Skip to content

[Repo Assist] Add AsyncSeq.transpose — mirror Seq.transpose for async sequences#271

Closed
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/improve-transpose-25d9ce964f872ff8
Closed

[Repo Assist] Add AsyncSeq.transpose — mirror Seq.transpose for async sequences#271
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/improve-transpose-25d9ce964f872ff8

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 9, 2026

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Adds AsyncSeq.transpose, a new combinator that mirrors [Seq.transpose]((fsharp.github.io/redacted) for async sequences.

Motivation

Seq.transpose is a useful utility for "rotating" a sequence of rows into a sequence of columns. This PR brings the same capability to AsyncSeq.

API

/// Transposes the rows and columns of an async sequence of sequences, yielding each
/// column as an array. Buffers the entire source sequence. Raises InvalidOperationException
/// if inner sequences have different lengths. Mirrors Seq.transpose.
val transpose : source:AsyncSeq(seq<'T)> -> AsyncSeq<'T[]>

Example:

let rows =
    asyncSeq {
        yield [| 1; 2; 3 |] :> seq(int)
        yield [| 4; 5; 6 |] :> seq(int)
    }
let cols = AsyncSeq.transpose rows |> AsyncSeq.toArrayAsync |> Async.RunSynchronously
// cols = [| [|1;4|]; [|2;5|]; [|3;6|] |]
```

## Implementation Notes

- Buffers all inner sequences to arrays first, then yields columns (same approach as `rev`).
- Raises `InvalidOperationException` with message `"The input sequences have different lengths."` for jagged inputs, matching `Seq.transpose` semantics.
- Placed under `#if !FABLE_COMPILER` (same as `rev`) since it depends on `toListAsync`.
- Accepts `AsyncSeq(seq<'T)>` so callers can pass `AsyncSeq<'T[]>`, `AsyncSeq(list<'T)>`, etc. with a coercion.

## Test Status

✅ **323/323 tests pass** (6 new `transpose` tests covering: basic 2×3 matrix, empty outer, single row, single column, singleton, and jagged-input error).

```
Passed! - Failed: 0, Passed: 323, Skipped: 0, Total: 323

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

Transposes rows and columns of an AsyncSeq<seq<'T>>, yielding each
column as a 'T array. Buffers all rows before yielding columns.
Raises InvalidOperationException if inner sequences have different lengths.

- Signature in AsyncSeq.fsi
- 6 tests covering basic transpose, empty, single row, single column,
  singleton, and jagged-input error case
- RELEASE_NOTES.md: 4.9.0 entry

323/323 tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme closed this Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant