diff --git a/src/FSharp.Control.AsyncSeq/AsyncSeq.fs b/src/FSharp.Control.AsyncSeq/AsyncSeq.fs index 9f609d1..909cc13 100644 --- a/src/FSharp.Control.AsyncSeq/AsyncSeq.fs +++ b/src/FSharp.Control.AsyncSeq/AsyncSeq.fs @@ -868,6 +868,9 @@ module AsyncSeq = member x.For (seq:AsyncSeq<'T>, action:'T -> AsyncSeq<'TResult>) = collect action seq + member x.YieldFrom (s:seq<'T>) = + ofSeq s + let unfoldAsync (f:'State -> Async<('T * 'State) option>) (s:'State) : AsyncSeq<'T> = new UnfoldAsyncEnumerator<_, _>(f, s) :> _ diff --git a/src/FSharp.Control.AsyncSeq/AsyncSeq.fsi b/src/FSharp.Control.AsyncSeq/AsyncSeq.fsi index 5d1554f..f801cc4 100644 --- a/src/FSharp.Control.AsyncSeq/AsyncSeq.fsi +++ b/src/FSharp.Control.AsyncSeq/AsyncSeq.fsi @@ -112,6 +112,9 @@ module AsyncSeq = /// Implements "yield!" for the asyncSeq computation builder. member YieldFrom : source:AsyncSeq<'T> -> AsyncSeq<'T> + /// Implements "yield!" for a synchronous sequence in the asyncSeq computation builder. + member YieldFrom : source:seq<'T> -> AsyncSeq<'T> + /// Implements empty for the asyncSeq computation builder. member Zero : unit -> AsyncSeq<'T> diff --git a/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs b/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs index e13a842..5dffd6f 100644 --- a/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs +++ b/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs @@ -156,6 +156,26 @@ let ``AsyncSeq.toListSynchronously``() = Assert.True(([1;2;3] = a)) +[] +let ``asyncSeq yield! seq works``() = + let items = seq { 1; 2; 3 } + let s = asyncSeq { + yield! items + } + let a = s |> AsyncSeq.toListSynchronously + Assert.True(([1;2;3] = a)) + +[] +let ``asyncSeq yield! seq combines with other yields``() = + let items = seq { 2; 3 } + let s = asyncSeq { + yield 1 + yield! items + yield 4 + } + let a = s |> AsyncSeq.toListSynchronously + Assert.True(([1;2;3;4] = a)) + [] let ``AsyncSeq.concatSeq works``() = let ls = [ [1;2] ; [3;4] ]