@@ -3141,3 +3141,71 @@ let ``AsyncSeq.tail on empty returns empty`` () =
31413141 |> AsyncSeq.toListAsync
31423142 |> Async.RunSynchronously
31433143 Assert.AreEqual([], result)
3144+
3145+ // ===== findAsync / existsAsync / forallAsync =====
3146+
3147+ [<Test>]
3148+ let ``AsyncSeq.findAsync returns matching element`` () =
3149+ for i in 0 .. 10 do
3150+ let ls = [ 1 .. i + 1 ]
3151+ let result =
3152+ AsyncSeq.ofSeq ls
3153+ |> AsyncSeq.findAsync ( fun x -> async { return x = i + 1 })
3154+ |> Async.RunSynchronously
3155+ Assert.AreEqual( i + 1 , result)
3156+
3157+ [<Test>]
3158+ let ``AsyncSeq.findAsync raises KeyNotFoundException when no match`` () =
3159+ Assert.Throws< System.Collections.Generic.KeyNotFoundException>( fun () ->
3160+ AsyncSeq.ofSeq [ 1 ; 2 ; 3 ]
3161+ |> AsyncSeq.findAsync ( fun x -> async { return x = 99 })
3162+ |> Async.RunSynchronously |> ignore)
3163+ |> ignore
3164+
3165+ [<Test>]
3166+ let ``AsyncSeq.existsAsync returns true when element found`` () =
3167+ let result =
3168+ AsyncSeq.ofSeq [ 1 ; 2 ; 3 ]
3169+ |> AsyncSeq.existsAsync ( fun x -> async { return x = 2 })
3170+ |> Async.RunSynchronously
3171+ Assert.IsTrue( result)
3172+
3173+ [<Test>]
3174+ let ``AsyncSeq.existsAsync returns false on empty sequence`` () =
3175+ let result =
3176+ AsyncSeq.empty< int>
3177+ |> AsyncSeq.existsAsync ( fun _ -> async { return true })
3178+ |> Async.RunSynchronously
3179+ Assert.IsFalse( result)
3180+
3181+ [<Test>]
3182+ let ``AsyncSeq.existsAsync returns false when no match`` () =
3183+ let result =
3184+ AsyncSeq.ofSeq [ 1 ; 2 ; 3 ]
3185+ |> AsyncSeq.existsAsync ( fun x -> async { return x = 99 })
3186+ |> Async.RunSynchronously
3187+ Assert.IsFalse( result)
3188+
3189+ [<Test>]
3190+ let ``AsyncSeq.forallAsync returns true when all match`` () =
3191+ let result =
3192+ AsyncSeq.ofSeq [ 2 ; 4 ; 6 ]
3193+ |> AsyncSeq.forallAsync ( fun x -> async { return x % 2 = 0 })
3194+ |> Async.RunSynchronously
3195+ Assert.IsTrue( result)
3196+
3197+ [<Test>]
3198+ let ``AsyncSeq.forallAsync returns false when some do not match`` () =
3199+ let result =
3200+ AsyncSeq.ofSeq [ 2 ; 3 ; 6 ]
3201+ |> AsyncSeq.forallAsync ( fun x -> async { return x % 2 = 0 })
3202+ |> Async.RunSynchronously
3203+ Assert.IsFalse( result)
3204+
3205+ [<Test>]
3206+ let ``AsyncSeq.forallAsync returns true on empty sequence`` () =
3207+ let result =
3208+ AsyncSeq.empty< int>
3209+ |> AsyncSeq.forallAsync ( fun _ -> async { return false })
3210+ |> Async.RunSynchronously
3211+ Assert.IsTrue( result)
0 commit comments