Skip to content

Commit

Permalink
Seq.sortWithStable is stable
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jul 29, 2015
1 parent 2149c2d commit 3c9e689
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/fsharp/FSharp.Core.PropertyTests/SeqProperties.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ let sortByStable<'a when 'a : comparison> (xs : 'a []) =
let ``Seq.sortBy is stable`` () =
Check.QuickThrowOnFailure sortByStable<int>
Check.QuickThrowOnFailure sortByStable<string>

let sortWithStable<'a when 'a : comparison> (xs : 'a []) =
let indexed = xs |> Seq.indexed |> Seq.toList
let sorted = indexed |> Seq.sortWith (fun x y -> compare (snd x) (snd y))
isStable sorted

[<Test>]
let ``Seq.sortWithStable is stable`` () =
Check.QuickThrowOnFailure sortWithStable<int>
Check.QuickThrowOnFailure sortWithStable<string>

let distinctByStable<'a when 'a : comparison> (xs : 'a []) =
let indexed = xs |> Seq.indexed
Expand Down

0 comments on commit 3c9e689

Please sign in to comment.