Skip to content

Commit 4724467

Browse files
Allow AsyncSeq.mergeAll to accept seq instead of list
Widen the parameter type of AsyncSeq.mergeAll from 'AsyncSeq<'T> list' to 'seq<AsyncSeq<'T>>'. This is backward-compatible since list implements seq in F#, but also allows callers to pass arrays, other collections, or lazy sequences without needing an explicit conversion. The implementation materialises the seq to an array immediately since random-access (indexed look-up) and Length are needed internally. Closes #165 Co-authored-by: Copilot <[email protected]>
1 parent 51fd03f commit 4724467

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/FSharp.Control.AsyncSeq/AsyncSeq.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,8 +1700,9 @@ module AsyncSeq =
17001700

17011701
/// Merges all specified async sequences into an async sequence non-deterministically.
17021702
// By moving the last emitted task to the end of the array, this algorithm achieves max-min fairness when merging AsyncSeqs
1703-
let mergeAll (ss:AsyncSeq<'T> list) : AsyncSeq<'T> =
1703+
let mergeAll (ss:seq<AsyncSeq<'T>>) : AsyncSeq<'T> =
17041704
asyncSeq {
1705+
let ss = Seq.toArray ss
17051706
let n = ss.Length
17061707

17071708
let moveToEnd i (a: 'a[]) =

src/FSharp.Control.AsyncSeq/AsyncSeq.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ module AsyncSeq =
502502

503503
/// Merges all specified async sequences into an async sequence non-deterministically.
504504
/// The resulting async sequence produces elements when any argument sequence produces an element.
505-
val mergeAll : sources:AsyncSeq<'T> list -> AsyncSeq<'T>
505+
val mergeAll : sources:seq<AsyncSeq<'T>> -> AsyncSeq<'T>
506506
#endif
507507

508508
/// Returns an async sequence which contains no contiguous duplicate elements based on the specified comparison function.

0 commit comments

Comments
 (0)