@@ -27,9 +27,31 @@ module EmptySeq =
2727 |> TaskSeq.toListAsync
2828 |> Task.map ( List.isEmpty >> should be True)
2929
30- module Terminates =
30+ // The primary requirement is that items after the item failing the predicate must be excluded
31+ module TakeWhileExcludesEverythingAfterFail =
3132 [<Fact>]
32- let ``TaskSeq - takeWhile stops after predicate fails`` () =
33+ let ``TaskSeq - takeWhile excludes all items after predicate fails`` () =
34+ seq { 1 ; 2 ; 2 ; 3 ; 2 ; 1 }
35+ |> TaskSeq.ofSeq
36+ |> TaskSeq.takeWhile ( fun x -> x <= 2 )
37+ |> TaskSeq.map char
38+ |> TaskSeq.map ((+) '@' )
39+ |> TaskSeq.toArrayAsync
40+ |> Task.map ( String >> should equal " AB" )
41+
42+ [<Fact>]
43+ let ``TaskSeq - takeWhileAsync excludes all items after after predicate fails`` () =
44+ taskSeq { 1 ; 2 ; 2 ; 3 ; 2 ; 1 }
45+ |> TaskSeq.takeWhileAsync ( fun x -> task { return x <= 2 })
46+ |> TaskSeq.map char
47+ |> TaskSeq.map ((+) '@' )
48+ |> TaskSeq.toArrayAsync
49+ |> Task.map ( String >> should equal " AB" )
50+
51+ // Covers the fact that it's not sufficient to merely exclude successor items - it's also critical that the enumeration terminates
52+ module TakeWhileTerminatesOnFail =
53+ [<Fact>]
54+ let ``TaskSeq - takeWhile stops consuming after predicate fails`` () =
3355 seq { 1 ; 2 ; 3 ; failwith " Too far" }
3456 |> TaskSeq.ofSeq
3557 |> TaskSeq.takeWhile ( fun x -> x <= 2 )
@@ -39,7 +61,7 @@ module Terminates =
3961 |> Task.map ( String >> should equal " AB" )
4062
4163 [<Fact>]
42- let ``TaskSeq - takeWhileAsync stops after predicate fails`` () =
64+ let ``TaskSeq - takeWhileAsync stops consuming after predicate fails`` () =
4365 taskSeq { 1 ; 2 ; 3 ; failwith " Too far" }
4466 |> TaskSeq.takeWhileAsync ( fun x -> task { return x <= 2 })
4567 |> TaskSeq.map char
0 commit comments