File tree Expand file tree Collapse file tree
src/FSharp.Control.AsyncSeq
tests/FSharp.Control.AsyncSeq.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11[ ![ Issue Stats] ( http://issuestats.com/github/fsprojects/FSharp.Control.AsyncSeq/badge/issue )] ( http://issuestats.com/github/fsprojects/FSharp.Control.AsyncSeq )
22[ ![ Issue Stats] ( http://issuestats.com/github/fsprojects/FSharp.Control.AsyncSeq/badge/pr )] ( http://issuestats.com/github/fsprojects/FSharp.Control.AsyncSeq )
3- [ ![ Build status] ( https://ci.appveyor.com/api/projects/status/k7lyn5rqeuqagyi2 /branch/master?svg=true )] ( https://ci.appveyor.com/project/SteffenForkmann/asyncseq/branch/master )
4- [ ![ Build status] ( https://travis-ci.org/fsprojects/FSharp.Control.AsyncSeq.svg?branch=master )] ( https://travis-ci.org/fsprojects/AsyncSeq )
3+ [ ![ Build status] ( https://ci.appveyor.com/api/projects/status/22wknie0x5c2jfuo /branch/master?svg=true )] ( https://ci.appveyor.com/project/SteffenForkmann/fsharp-control- asyncseq/branch/master )
4+ [ ![ Build status] ( https://travis-ci.org/fsprojects/FSharp.Control.AsyncSeq.svg?branch=master )] ( https://travis-ci.org/fsprojects/FSharp.Control. AsyncSeq )
55
66# FSharp.Control.AsyncSeq [ ![ NuGet Status] ( http://img.shields.io/nuget/v/FSharp.Control.AsyncSeq.svg?style=flat )] ( https://www.nuget.org/packages/FSharp.Control.AsyncSeq/ )
77
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ module AsyncSeq =
136136 // do! something
137137 //
138138 // because F# translates body as Bind(something, fun () -> Return())
139- member x.Return () = empty
139+ member x.Return _ = empty
140140 member x.YieldFrom ( s ) = s
141141 member x.Zero () = empty
142142 member x.Bind ( inp : Async < 'T >, body : 'T -> AsyncSeq < 'U >) : AsyncSeq < 'U > =
@@ -255,14 +255,16 @@ module AsyncSeq =
255255 | Nil -> return def
256256 | Cons( h, _) -> return h }
257257
258- let rec scanAsync f ( state : 'State ) ( input : AsyncSeq < 'T >) = asyncSeq {
259- let! v = input
260- match v with
261- | Nil -> ()
262- | Cons( h, t) ->
258+ let scanAsync f ( state : 'TState ) ( input : AsyncSeq < 'T >) =
259+ let rec go f state s = asyncSeq {
260+ let! v = s
261+ match v with
262+ | Nil -> ()
263+ | Cons( h, t) ->
263264 let! v = f state h
264265 yield v
265- yield ! t |> scanAsync f v }
266+ yield ! t |> go f v }
267+ asyncSeq { yield state ; yield ! go f state input }
266268
267269 let iterAsync f ( input : AsyncSeq < 'T >) = async {
268270 for itm in input do
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ module AsyncSeq =
5959 member For : seq : AsyncSeq < 'T > * action :( 'T -> AsyncSeq < 'TResult >) -> AsyncSeq < 'TResult >
6060
6161 /// Implements "return " for the asyncSeq computation builder.
62- member Return : unit -> AsyncSeq < 'T >
62+ member Return : ' unit -> AsyncSeq < 'T >
6363
6464 /// Implements "try - finally " for the asyncSeq computation builder.
6565 member TryFinally : body : AsyncSeq < 'T > * compensation :( unit -> unit ) -> AsyncSeq < 'T >
Original file line number Diff line number Diff line change @@ -153,7 +153,16 @@ let ``AsyncSeq.scanAsync``() =
153153 let f i a = i + a
154154 let z = 0
155155 let actual = ls |> AsyncSeq.ofSeq |> AsyncSeq.scanAsync ( fun i a -> f i a |> async.Return) z
156- let expected = ls |> Seq.scan f z |> Seq.skip 1 |> AsyncSeq.ofSeq
156+ let expected = ls |> List.scan f z |> AsyncSeq.ofSeq
157+ Assert.True( EQ expected actual)
158+
159+ [<Test>]
160+ let ``AsyncSeq.scanAsync on empty should emit initial state`` () =
161+ let ls = List.empty
162+ let f i a = i + a
163+ let z = 0
164+ let actual = ls |> AsyncSeq.ofSeq |> AsyncSeq.scanAsync ( fun i a -> f i a |> async.Return) z
165+ let expected = ls |> List.scan f z |> AsyncSeq.ofSeq
157166 Assert.True( EQ expected actual)
158167
159168
@@ -291,7 +300,6 @@ let ``AsyncSeq.skipUntil should skip everything with never signal``() =
291300 let actual = [ 1 ; 2 ; 3 ; 4 ] |> AsyncSeq.ofSeq |> AsyncSeq.skipUntil AsyncOps.never
292301 Assert.True( EQ AsyncSeq.empty actual)
293302
294-
295303[<Test>]
296304let ``AsyncSeq.toBlockingSeq should work length 1`` () =
297305 let s = asyncSeq { yield 1 } |> AsyncSeq.toBlockingSeq |> Seq.toList
@@ -349,3 +357,11 @@ let ``AsyncSeq.toBlockingSeq should be cancellable``() =
349357 System.Threading.Thread.Sleep( 1000 ) // wait for task cancellation to be effective
350358 Assert.AreEqual( cancelCount.Value, 1 )
351359
360+ [<Test>]
361+ let ``AsyncSeq.while should allow do at end`` () =
362+ let s1 = asyncSeq {
363+ while false do
364+ yield 1
365+ do ! Async.Sleep 10
366+ }
367+ Assert.True( true )
You can’t perform that action at this time.
0 commit comments