Skip to content

Commit 3c60d5f

Browse files
committed
Return array
1 parent 928a68d commit 3c60d5f

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/FSharp.Control.AsyncSeq/AsyncSeq.fs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,19 +1484,19 @@ module AsyncSeq =
14841484
yield buffer.ToArray() }
14851485

14861486
let toSortedSeq fn source =
1487-
toArrayAsync source |> Async.map (fun source' -> (fn source' :> seq<'T>)) |> Async.RunSynchronously
1487+
toArrayAsync source |> Async.map fn |> Async.RunSynchronously
14881488

1489-
let sort (source:AsyncSeq<'T>) : seq<'T> when 'T : comparison =
1490-
toSortedSeq Seq.sort source
1489+
let sort (source:AsyncSeq<'T>) : array<'T> when 'T : comparison =
1490+
toSortedSeq Array.sort source
14911491

1492-
let sortBy (projection:'T -> 'Key) (source:AsyncSeq<'T>) : seq<'T> when 'Key : comparison =
1493-
toSortedSeq (Seq.sortBy projection) source
1492+
let sortBy (projection:'T -> 'Key) (source:AsyncSeq<'T>) : array<'T> when 'Key : comparison =
1493+
toSortedSeq (Array.sortBy projection) source
14941494

1495-
let sortDescending (source:AsyncSeq<'T>) : seq<'T> when 'T : comparison =
1496-
toSortedSeq Seq.sortDescending source
1495+
let sortDescending (source:AsyncSeq<'T>) : array<'T> when 'T : comparison =
1496+
toSortedSeq Array.sortDescending source
14971497

1498-
let sortByDescending (projection:'T -> 'Key) (source:AsyncSeq<'T>) : seq<'T> when 'Key : comparison =
1499-
toSortedSeq (Seq.sortByDescending projection) source
1498+
let sortByDescending (projection:'T -> 'Key) (source:AsyncSeq<'T>) : array<'T> when 'Key : comparison =
1499+
toSortedSeq (Array.sortByDescending projection) source
15001500

15011501
#if !FABLE_COMPILER
15021502
let bufferByCountAndTime (bufferSize:int) (timeoutMs:int) (source:AsyncSeq<'T>) : AsyncSeq<'T[]> =

src/FSharp.Control.AsyncSeq/AsyncSeq.fsi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,25 +441,25 @@ module AsyncSeq =
441441
/// This function returns a sequence that digests the whole initial sequence as soon as
442442
/// that sequence is iterated. As a result this function should not be used with
443443
/// large or infinite sequences.
444-
val sort : source:AsyncSeq<'T> -> seq<'T> when 'T : comparison
444+
val sort : source:AsyncSeq<'T> -> array<'T> when 'T : comparison
445445

446-
/// Applies a key-generating function to each element of an AsyncSeq and yield a sequence ordered by keys.
447-
/// This function returns a sequence that digests the whole initial sequence as soon as
446+
/// Applies a key-generating function to each element of an AsyncSeq and yield an array ordered by keys.
447+
/// This function returns an array that digests the whole initial sequence as soon as
448448
/// that sequence is iterated. As a result this function should not be used with
449449
/// large or infinite sequences.
450-
val sortBy : projection:('T -> 'Key) -> source:AsyncSeq<'T> -> seq<'T> when 'Key : comparison
450+
val sortBy : projection:('T -> 'Key) -> source:AsyncSeq<'T> -> array<'T> when 'Key : comparison
451451

452-
/// Yields a sequence ordered descending by keys.
453-
/// This function returns a sequence that digests the whole initial sequence as soon as
452+
/// Yields an array ordered descending by keys.
453+
/// This function returns an array that digests the whole initial sequence as soon as
454454
/// that sequence is iterated. As a result this function should not be used with
455455
/// large or infinite sequences.
456-
val sortDescending : source:AsyncSeq<'T> -> seq<'T> when 'T : comparison
456+
val sortDescending : source:AsyncSeq<'T> -> array<'T> when 'T : comparison
457457

458-
/// Applies a key-generating function to each element of an AsyncSeq and yield a sequence ordered descending by keys.
459-
/// This function returns a sequence that digests the whole initial sequence as soon as
458+
/// Applies a key-generating function to each element of an AsyncSeq and yield an array ordered descending by keys.
459+
/// This function returns an array that digests the whole initial sequence as soon as
460460
/// that sequence is iterated. As a result this function should not be used with
461461
/// large or infinite sequences.
462-
val sortByDescending : projection:('T -> 'Key) -> source:AsyncSeq<'T> -> seq<'T> when 'Key : comparison
462+
val sortByDescending : projection:('T -> 'Key) -> source:AsyncSeq<'T> -> array<'T> when 'Key : comparison
463463

464464
/// Interleaves two async sequences of the same type into a resulting sequence. The provided
465465
/// sequences are consumed in lock-step.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,30 +1736,30 @@ let ``Async.concat should work``() =
17361736
[<Test>]
17371737
let ``AsyncSeq.sort should work for``() =
17381738
let input = [1; 3; 2; 5; 7; 4; 6] |> AsyncSeq.ofSeq
1739-
let expected = [1..7]
1739+
let expected = [|1..7|]
17401740
let actual = input |> AsyncSeq.sort
17411741
Assert.AreEqual(expected, actual)
17421742

17431743
[<Test>]
17441744
let ``AsyncSeq.sortDescending should work``() =
17451745
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 }
1746+
let expected = seq { yield Int32.MaxValue; yield! seq{ 7..-1..0 }; yield Int32.MinValue } |> Array.ofSeq
17471747
let actual = input |> AsyncSeq.sortDescending
17481748
Assert.AreEqual(expected, actual)
17491749

17501750
[<Test>]
17511751
let ``AsyncSeq.sortBy should work``() =
17521752
let fn x = Math.Abs(x-5)
17531753
let input = [1; 2; 4; 5; 7] |> AsyncSeq.ofSeq
1754-
let expected = [5; 4; 7; 2; 1]
1754+
let expected = [|5; 4; 7; 2; 1|]
17551755
let actual = input |> AsyncSeq.sortBy fn
17561756
Assert.AreEqual(expected, actual)
17571757

17581758
[<Test>]
17591759
let ``AsyncSeq.sortByDescending should work``() =
17601760
let fn x = Math.Abs(x-5)
17611761
let input = [1; 2; 4; 5; 6; 7;] |> AsyncSeq.ofSeq
1762-
let expected = [1; 2; 7; 4; 6; 5;]
1762+
let expected = [|1; 2; 7; 4; 6; 5;|]
17631763
let actual = input |> AsyncSeq.sortByDescending fn
17641764
Assert.AreEqual(expected, actual)
17651765

0 commit comments

Comments
 (0)