Skip to content

Commit 33fd3a6

Browse files
committed
Merge pull request #2 from danielrbradley/fix-async-seq-skip-bug
Fix bug where AsyncSeq.skipWhile skips an extra item
2 parents 7c15018 + 0411dca commit 33fd3a6

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/FSharpx.Async/AsyncSeq.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ module AsyncSeq =
439439
let rec skipWhileAsync p (input : AsyncSeq<'T>) : AsyncSeq<_> = async {
440440
let! v = input
441441
match v with
442-
| Cons(h, t) ->
442+
| Cons(h, t) ->
443443
let! res = p h
444444
if res then return! skipWhileAsync p t
445-
else return! t
445+
else return v
446446
| Nil -> return Nil }
447447

448448
/// Returns elements from an asynchronous sequence while the specified
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module AsyncSeqTests
2+
3+
open NUnit.Framework
4+
open FSharpx.Control
5+
6+
[<Test>]
7+
let ``skipping should return all elements after the first non-match``() =
8+
let expected = [ 3; 4 ]
9+
let result =
10+
[ 1; 2; 3; 4 ]
11+
|> AsyncSeq.ofSeq
12+
|> AsyncSeq.skipWhile (fun i -> i <= 2)
13+
|> AsyncSeq.toBlockingSeq
14+
|> Seq.toList
15+
Assert.AreEqual(expected, result)

tests/FSharpx.Async.Tests/FSharpx.Async.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
5959
<ItemGroup>
6060
<Compile Include="AsyncTest.fs" />
61+
<Compile Include="AsyncSeqTests.fs" />
6162
<None Include="paket.references" />
6263
</ItemGroup>
6364
<ItemGroup>

0 commit comments

Comments
 (0)