Skip to content

Commit 75045b1

Browse files
committed
simplify ofObservableBuffered and toBlockingSeq
2 parents 09757c9 + d2e3dc9 commit 75045b1

6 files changed

Lines changed: 45 additions & 7 deletions

File tree

RELEASE_NOTES.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
### 1.16.0 - 13.05.2015
2+
* Simplify ofObservableBuffered and toBlockingSeq
3+
4+
### 1.15.0 - 30.03.2015
5+
* Add AsyncSeq.getIterator (unblocks use of AsyncSeq in FSharpx.Async)
6+
7+
### 1.14 - 30.03.2015
8+
* Cancellable AsyncSeq.toBlockingSeq
9+
* Fix AsyncSeq.scanAsync to also return first state
10+
* Add a signature file
11+
* AsyncSeq got extracted as separate project and is now a dependency - https://github.com/fsprojects/FSharpx.Async/pull/24
12+
113
### 1.13 - 27.03.2015
214
* Renamed to FSharp.Control.AsyncSeq
315
* Remove surface area

docs/content/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ FSharp.Control.AsyncSeq is a collection of asynchronous programming utilities fo
77
<div class="span1"></div>
88
<div class="span6">
99
<div class="well well-small" id="nuget">
10-
The FSharp.Control.AsyncSeq library can be <a href="https://nuget.org/packages/AsyncSeq">installed from NuGet</a>:
10+
The FSharp.Control.AsyncSeq library can be <a href="http://www.nuget.org/packages/FSharp.Control.AsyncSeq">installed from NuGet</a>:
1111
<pre>PM> Install-Package FSharp.Control.AsyncSeq</pre>
1212
</div>
1313
</div>

src/FSharp.Control.AsyncSeq/AssemblyInfo.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ open System.Reflection
44
[<assembly: AssemblyTitleAttribute("FSharp.Control.AsyncSeq")>]
55
[<assembly: AssemblyProductAttribute("FSharp.Control.AsyncSeq")>]
66
[<assembly: AssemblyDescriptionAttribute("Asynchronous sequences for F#")>]
7-
[<assembly: AssemblyVersionAttribute("1.13")>]
8-
[<assembly: AssemblyFileVersionAttribute("1.13")>]
7+
[<assembly: AssemblyVersionAttribute("1.15.0")>]
8+
[<assembly: AssemblyFileVersionAttribute("1.15.0")>]
99
do ()
1010

1111
module internal AssemblyVersionInformation =
12-
let [<Literal>] Version = "1.13"
12+
let [<Literal>] Version = "1.15.0"

src/FSharp.Control.AsyncSeq/AsyncSeq.fs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ module AsyncSeq =
286286
let fold f (state:'State) (input : AsyncSeq<'T>) =
287287
foldAsync (fun st v -> f st v |> async.Return) state input
288288

289-
let rec scan f (state:'State) (input : AsyncSeq<'T>) =
289+
let scan f (state:'State) (input : AsyncSeq<'T>) =
290290
scanAsync (fun st v -> f st v |> async.Return) state input
291291

292292
let map f (input : AsyncSeq<'T>) =
@@ -608,7 +608,14 @@ module AsyncSeq =
608608

609609
let distinctUntilChanged (s:AsyncSeq<'T>) : AsyncSeq<'T> =
610610
distinctUntilChangedWith ((=)) s
611-
611+
612+
let getIterator (s:AsyncSeq<'T>) =
613+
let curr = ref s
614+
fun () ->
615+
async { let! v = curr.Value
616+
match v with
617+
| Nil -> return None
618+
| Cons (v,t) -> curr := t; return Some v }
612619

613620

614621

src/FSharp.Control.AsyncSeq/AsyncSeq.fsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ module AsyncSeq =
300300
/// Returns an async sequence which contains no contiguous duplicate elements.
301301
val distinctUntilChanged : s:AsyncSeq<'T> -> AsyncSeq<'T> when 'T : equality
302302

303-
303+
/// Get a function that may be usesd as an async iterator for the sequence. This functionality may be replaced in later versions of this library.
304+
val getIterator : s:AsyncSeq<'T> -> (unit -> Async<'T option>)
304305

305306
/// An automatically-opened module tht contains the `asyncSeq` builder and an extension method
306307
[<AutoOpen>]

tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,21 @@ let ``AsyncSeq.ofObservableBuffered should work (one, take)``() =
414414
Assert.True(src |> AsyncSeq.ofObservableBuffered |> AsyncSeq.take 1 |> AsyncSeq.toList |> Async.RunSynchronously = [1])
415415
// Take doesn't correctly run finally clauses, see https://github.com/fsprojects/FSharp.Control.AsyncSeq/issues/15
416416
//Assert.True(discarded())
417+
418+
[<Test>]
419+
let ``AsyncSeq.getIterator should work``() =
420+
let s1 = [1..2] |> AsyncSeq.ofSeq
421+
let i = AsyncSeq.getIterator s1
422+
match i() |> Async.RunSynchronously with
423+
| None -> Assert.Fail("expected Some")
424+
| Some v ->
425+
Assert.AreEqual(v,1)
426+
match i() |> Async.RunSynchronously with
427+
| None -> Assert.Fail("expected Some")
428+
| Some v ->
429+
Assert.AreEqual(v,2)
430+
match i() |> Async.RunSynchronously with
431+
| None -> ()
432+
| Some _ -> Assert.Fail("expected None")
433+
434+

0 commit comments

Comments
 (0)