File tree Expand file tree Collapse file tree
tests/FSharpx.Async.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -496,6 +496,16 @@ module AsyncSeq =
496496 yield ! unfoldAsync f s
497497 | None -> () }
498498
499+ /// Flattens an AsyncSeq of sequences.
500+ let rec concatSeq ( input : AsyncSeq < #seq < 'T >>) : AsyncSeq < 'T > = asyncSeq {
501+ let! v = input
502+ match v with
503+ | Nil -> ()
504+ | Cons ( hd, tl) ->
505+ for item in hd do
506+ yield item
507+ yield ! concatSeq tl }
508+
499509[<AutoOpen>]
500510module AsyncSeqExtensions =
501511 /// Builds an asynchronou sequence using the computation builder syntax
Original file line number Diff line number Diff line change @@ -43,6 +43,24 @@ let ``toList should collect the results into an array``() =
4343 Assert.True(([ 1 ; 2 ; 3 ] = a))
4444
4545
46+ [<Test>]
47+ let ``concatSeq should flatten a sequence`` () =
48+
49+ let s = asyncSeq {
50+ yield [ 1 ; 2 ]
51+ yield [ 3 ; 4 ]
52+ }
53+
54+ let s =
55+ s
56+ |> AsyncSeq.concatSeq
57+ |> AsyncSeq.toList
58+ |> Async.RunSynchronously
59+
60+ Assert.True(([ 1 ; 2 ; 3 ; 4 ] = s))
61+
62+
63+
4664[<Test>]
4765let ``unfoldAsync should generate a sequence`` () =
4866
You can’t perform that action at this time.
0 commit comments