@@ -1512,18 +1512,18 @@ let ``AsyncSeq.iterAsyncParallel should propagate exception`` () =
15121512
15131513[<Test>]
15141514let ``AsyncSeq.iterAsyncParallel should cancel and not block forever when run in parallel with another exception - throwing Async`` () =
1515-
1515+
15161516 let handle x = async {
1517- do ! Async.Sleep 50
1517+ do ! Async.Sleep 50
15181518 }
15191519
1520- let fakeAsync = async {
1520+ let fakeAsync = async {
15211521 do ! Async.Sleep 500
15221522 return " fakeAsync"
15231523 }
15241524
15251525 let makeAsyncSeqBatch () =
1526- let rec loop () = asyncSeq {
1526+ let rec loop () = asyncSeq {
15271527 let! batch = fakeAsync |> Async.Catch
15281528 match batch with
15291529 | Choice1Of2 batch ->
@@ -1532,11 +1532,11 @@ let ``AsyncSeq.iterAsyncParallel should cancel and not block forever when run in
15321532 yield ! loop()
15331533 else
15341534 yield batch
1535- yield ! loop()
1535+ yield ! loop()
15361536 | Choice2Of2 err ->
15371537 printfn " Problem getting batch: %A " err
15381538 }
1539-
1539+
15401540 loop()
15411541
15421542 let x = makeAsyncSeqBatch () |> AsyncSeq.concatSeq |> AsyncSeq.iterAsyncParallel handle
@@ -1733,6 +1733,36 @@ let ``Async.concat should work``() =
17331733
17341734 Assert.True( EQ expected actual)
17351735
1736+ [<Test>]
1737+ let ``AsyncSeq.sort should work for`` () =
1738+ let input = [ 1 ; 3 ; 2 ; 5 ; 7 ; 4 ; 6 ] |> AsyncSeq.ofSeq
1739+ let expected = [| 1 .. 7 |]
1740+ let actual = input |> AsyncSeq.sort
1741+ Assert.AreEqual( expected, actual)
1742+
1743+ [<Test>]
1744+ let ``AsyncSeq.sortDescending should work`` () =
1745+ let input = [ 1 ; 3 ; 2 ; Int32.MaxValue; 4 ; 6 ; Int32.MinValue; 5 ; 7 ; 0 ] |> AsyncSeq.ofSeq
1746+ let expected = seq { yield Int32.MaxValue; yield ! seq { 7 ..- 1 .. 0 }; yield Int32.MinValue } |> Array.ofSeq
1747+ let actual = input |> AsyncSeq.sortDescending
1748+ Assert.AreEqual( expected, actual)
1749+
1750+ [<Test>]
1751+ let ``AsyncSeq.sortBy should work`` () =
1752+ let fn x = Math.Abs( x-5 )
1753+ let input = [ 1 ; 2 ; 4 ; 5 ; 7 ] |> AsyncSeq.ofSeq
1754+ let expected = [| 5 ; 4 ; 7 ; 2 ; 1 |]
1755+ let actual = input |> AsyncSeq.sortBy fn
1756+ Assert.AreEqual( expected, actual)
1757+
1758+ [<Test>]
1759+ let ``AsyncSeq.sortByDescending should work`` () =
1760+ let fn x = Math.Abs( x-5 )
1761+ let input = [ 1 ; 2 ; 4 ; 5 ; 6 ; 7 ;] |> AsyncSeq.ofSeq
1762+ let expected = [| 1 ; 2 ; 7 ; 4 ; 6 ; 5 ;|]
1763+ let actual = input |> AsyncSeq.sortByDescending fn
1764+ Assert.AreEqual( expected, actual)
1765+
17361766#if ( NETSTANDARD2_ 1 || NETCOREAPP3_ 0)
17371767[<Test>]
17381768let ``AsyncSeq.ofAsyncEnum should roundtrip successfully`` () =
@@ -1744,8 +1774,8 @@ let ``AsyncSeq.ofAsyncEnum should roundtrip successfully``() =
17441774let ``AsyncSeq.toAsyncEnum raises exception`` () : unit =
17451775 async {
17461776 let exceptionMessage = " Raised inside AsyncSeq"
1747- let exceptionSequence =
1748- asyncSeq { yield failwith exceptionMessage; yield 1 }
1777+ let exceptionSequence =
1778+ asyncSeq { yield failwith exceptionMessage; yield 1 }
17491779 |> AsyncSeq.toAsyncEnum
17501780 let mutable exceptionRaised = false
17511781 try
@@ -1765,9 +1795,9 @@ let ``AsyncSeq.toAsyncEnum raises exception``() : unit =
17651795let ``AsyncSeq.ofAsyncEnum raises exception`` () : unit =
17661796 async {
17671797 let exceptionMessage = " Raised inside AsyncSeq"
1768- let exceptionSequence =
1769- asyncSeq { yield failwith exceptionMessage; yield 1 }
1770- |> AsyncSeq.toAsyncEnum
1798+ let exceptionSequence =
1799+ asyncSeq { yield failwith exceptionMessage; yield 1 }
1800+ |> AsyncSeq.toAsyncEnum
17711801 |> AsyncSeq.ofAsyncEnum
17721802 let mutable exceptionRaised = false
17731803 try
0 commit comments