Skip to content

Commit 6be8878

Browse files
committed
Add getIterator
1 parent b999f2e commit 6be8878

5 files changed

Lines changed: 40 additions & 6 deletions

File tree

RELEASE_NOTES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### 1.15.0 - 30.03.2015
2+
* Add AsyncSeq.getIterator (unblocks use of AsyncSeq in FSharpx.Async)
3+
4+
### 1.14 - 30.03.2015
5+
* Cancellable AsyncSeq.toBlockingSeq
6+
* Fix AsyncSeq.scanAsync to also return first state
7+
* Add a signature file
8+
19
### 1.13 - 27.03.2015
210
* Renamed to FSharp.Control.AsyncSeq
311
* Remove surface area

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>) =
@@ -649,7 +649,14 @@ module AsyncSeq =
649649

650650
let distinctUntilChanged (s:AsyncSeq<'T>) : AsyncSeq<'T> =
651651
distinctUntilChangedWith ((=)) s
652-
652+
653+
let getIterator (s:AsyncSeq<'T>) =
654+
let curr = ref s
655+
fun () ->
656+
async { let! v = curr.Value
657+
match v with
658+
| Nil -> return None
659+
| Cons (v,t) -> curr := t; return Some v }
653660

654661

655662

src/FSharp.Control.AsyncSeq/AsyncSeq.fsi

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

306-
306+
/// 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.
307+
val getIterator : s:AsyncSeq<'T> -> (unit -> Async<'T option>)
307308

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,21 @@ let ``AsyncSeq.while should allow do at end``() =
365365
do! Async.Sleep 10
366366
}
367367
Assert.True(true)
368+
369+
[<Test>]
370+
let ``AsyncSeq.getIterator should work``() =
371+
let s1 = [1..2] |> AsyncSeq.ofSeq
372+
let i = AsyncSeq.getIterator s1
373+
match i() |> Async.RunSynchronously with
374+
| None -> Assert.Fail("expected Some")
375+
| Some v ->
376+
Assert.AreEqual(v,1)
377+
match i() |> Async.RunSynchronously with
378+
| None -> Assert.Fail("expected Some")
379+
| Some v ->
380+
Assert.AreEqual(v,2)
381+
match i() |> Async.RunSynchronously with
382+
| None -> ()
383+
| Some _ -> Assert.Fail("expected None")
384+
385+

0 commit comments

Comments
 (0)