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 @@ -4,9 +4,9 @@ open System.Reflection
44[<assembly: AssemblyTitleAttribute( " FSharpx.Async" ) >]
55[<assembly: AssemblyProductAttribute( " FSharpx.Async" ) >]
66[<assembly: AssemblyDescriptionAttribute( " Async extensions for F#" ) >]
7- [<assembly: AssemblyVersionAttribute( " 1.9.8 " ) >]
8- [<assembly: AssemblyFileVersionAttribute( " 1.9.8 " ) >]
7+ [<assembly: AssemblyVersionAttribute( " 1.9.9 " ) >]
8+ [<assembly: AssemblyFileVersionAttribute( " 1.9.9 " ) >]
99do ()
1010
1111module internal AssemblyVersionInformation =
12- let [<Literal>] Version = " 1.9.8 "
12+ let [<Literal>] Version = " 1.9.9 "
Original file line number Diff line number Diff line change @@ -487,6 +487,14 @@ module AsyncSeq =
487487 let toList ( input : AsyncSeq < 'T >) : Async < 'T list > =
488488 input |> fold ( fun arr a -> a:: arr) []
489489
490+ /// Generates an async sequence using the specified generator function.
491+ let rec unfoldAsync ( f : 'State -> Async <( 'T * 'State ) option >) ( s : 'State ) : AsyncSeq < 'T > = asyncSeq {
492+ let! r = f s
493+ match r with
494+ | Some ( a, s) ->
495+ yield a
496+ yield ! unfoldAsync f s
497+ | None -> () }
490498
491499[<AutoOpen>]
492500module AsyncSeqExtensions =
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ let ``toArray should collect the results into an array``() =
2828
2929 Assert.True(([ 1 ; 2 ; 3 ] = a))
3030
31+
3132[<Test>]
3233let ``toList should collect the results into an array`` () =
3334
@@ -41,5 +42,19 @@ let ``toList should collect the results into an array``() =
4142
4243 Assert.True(([ 1 ; 2 ; 3 ] = a))
4344
44-
45+
46+ [<Test>]
47+ let ``unfoldAsync should generate a sequence`` () =
48+
49+ let gen s =
50+ if s < 3 then ( s, s + 1 ) |> Some |> async.Return
51+ else None |> async.Return
52+
53+ let s =
54+ AsyncSeq.unfoldAsync gen 0
55+ |> AsyncSeq.toList
56+ |> Async.RunSynchronously
57+
58+ Assert.True(([ 0 ; 1 ; 2 ] = s))
59+
4560
You can’t perform that action at this time.
0 commit comments