Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ae5c70

Browse files
PatrickMcDonaldlatkin
authored andcommitted
Implement Seq.sortWith and refactor various sorts to share code
Commits: Implement Seq.sortWith Modify Seq.sortWith and Array.stableSortInPlaceWith to remove comparison constraint on 'T Refactor List.sortWith to use Array.stableSortInPlaceWith Change signature of Array.stableSortInPlaceWith Push FSharpFunc.Adapt + new IComparer back into method Modify sortDescending and sortByDescending in Seq and List to use Array.stableSortinPlaceWith Get tests passing and add some more Re-remove dead List StableSortImplementation module (was re-added in rebase of sortWith) Change sortDescending and sortByDescending to inline - check explicitly for nan in comparer function - call sortWith implementations Revert NaN special casing in sortDescending Remove NaN from sortDescending tests NaN behavior is now "undefined" Update portable surface area tests Workarounds to avoid adding a comparison constraint on portable profiles Adding a few more tests
1 parentb446e2c commit6ae5c70

File tree

13 files changed

+193
-137
lines changed

13 files changed

+193
-137
lines changed

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule2.fs‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,10 @@ type ArrayModule2() =
700700
Assert.AreEqual([|DateTime(2015,1,1);DateTime(2014,12,31);DateTime(2014,1,1);DateTime(2014,1,1);DateTime(2013,12,31)|], resultDate)
701701

702702
// float array
703-
letfloatArr=[|0.5;2.0; nan;1.5;1.0|]
704-
letresultFloat= Array.sortDescending floatArr
705-
Assert.AreEqual([|2.0;1.5;1.0;0.5; nan;|], resultFloat)
703+
letminFloat,maxFloat,epsilon= System.Double.MinValue,System.Double.MaxValue,System.Double.Epsilon
704+
letfloatArr=[|0.0;0.5;2.0;1.5;1.0; minFloat; maxFloat; epsilon;-epsilon|]
705+
letresultFloat= Array.sortDescending floatArr
706+
Assert.AreEqual([| maxFloat;2.0;1.5;1.0;0.5; epsilon;0.0;-epsilon; minFloat;|], resultFloat)
706707

707708
()
708709

@@ -726,16 +727,22 @@ type ArrayModule2() =
726727
if resultEmpty<>[||]then Assert.Fail()
727728

728729
// tuple array
729-
lettupArr=[|(2,"a");(1,"d");(1,"b");(1,"a");(2,"x");(2,"b");(1,"x")|]
730+
lettupArr=[|(2,"a");(1,"d");(1,"b");(2,"x")|]
730731
letsndTup= Array.sortByDescending snd tupArr
731-
Assert.AreEqual([|(2,"a");(1,"d");(1,"b");(1,"a");(2,"x");(2,"b");(1,"x")|], tupArr)
732-
Assert.AreEqual([|(2,"x");(1,"x");(1,"d");(1,"b");(2,"b");(2,"a");(1,"a")|], sndTup)
732+
Assert.AreEqual([|(2,"a");(1,"d");(1,"b");(2,"x")|], tupArr)
733+
Assert.AreEqual([|(2,"x");(1,"d");(1,"b");(2,"a")|], sndTup)
733734

734735
// date array
735-
letdateArr=[|DateTime(2013,12,31);DateTime(2014,2,1);DateTime(2015,1,1);DateTime(2014,12,31);DateTime(2014,3,1)|]
736+
letdateArr=[|DateTime(2013,12,31);DateTime(2014,2,1);DateTime(2015,1,1);DateTime(2014,3,1)|]
736737
letresultDate= Array.sortByDescending(fun(d:DateTime)-> d.Month) dateArr
737-
Assert.AreEqual([|DateTime(2013,12,31);DateTime(2014,2,1);DateTime(2015,1,1);DateTime(2014,12,31);DateTime(2014,3,1)|], dateArr)
738-
Assert.AreEqual([|DateTime(2013,12,31);DateTime(2014,12,31);DateTime(2014,3,1);DateTime(2014,2,1);DateTime(2015,1,1)|], resultDate)
738+
Assert.AreEqual([|DateTime(2013,12,31);DateTime(2014,2,1);DateTime(2015,1,1);DateTime(2014,3,1)|], dateArr)
739+
Assert.AreEqual([|DateTime(2013,12,31);DateTime(2014,3,1);DateTime(2014,2,1);DateTime(2015,1,1)|], resultDate)
740+
741+
// float array
742+
letminFloat,maxFloat,epsilon= System.Double.MinValue,System.Double.MaxValue,System.Double.Epsilon
743+
letfloatArr=[|0.0;0.5;2.0;1.5;1.0; minFloat; maxFloat; epsilon;-epsilon|]
744+
letresultFloat= Array.sortByDescending id floatArr
745+
Assert.AreEqual([| maxFloat;2.0;1.5;1.0;0.5; epsilon;0.0;-epsilon; minFloat;|], resultFloat)
739746

740747
()
741748

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,11 @@ type ListModule02() =
606606

607607
[<Test>]
608608
memberthis.SortDescending()=
609-
// integer List
610-
letintArr=[3;5;7;2;4;8]
609+
// integer List
610+
letminInt,maxInt= System.Int32.MinValue,System.Int32.MaxValue
611+
letintArr=[3;5;7;2;4;8;0;-1;1;minInt;maxInt]
611612
letresultInt= List.sortDescending intArr
612-
Assert.AreEqual(resultInt,[8;7;5;4;3;2])
613+
Assert.AreEqual(resultInt,[maxInt;8;7;5;4;3;2;1;0;-1;minInt])
613614

614615
// string List
615616
letstrArr=["Z";"a";"d";"Y";"c";"b";"X"]
@@ -626,6 +627,13 @@ type ListModule02() =
626627
letresultTup= List.sortDescending tupArr
627628
Assert.AreEqual([(2,"x");(2,"b");(2,"a");(1,"x");(1,"d");(1,"b");(1,"a")], resultTup)
628629

630+
// float Seq
631+
letminFloat,maxFloat,epsilon= System.Double.MinValue,System.Double.MaxValue,System.Double.Epsilon
632+
letfloatArr=[0.0;0.5;2.0;1.5;1.0; minFloat;maxFloat;epsilon;-epsilon]
633+
letresultFloat= List.sortDescending floatArr
634+
letexpectedFloat=[maxFloat;2.0;1.5;1.0;0.5; epsilon;0.0;-epsilon; minFloat;]
635+
Assert.AreEqual(expectedFloat, resultFloat)
636+
629637
()
630638

631639
[<Test>]
@@ -650,8 +658,33 @@ type ListModule02() =
650658
letresultTup= List.sortByDescending snd tupArr
651659
Assert.AreEqual([(2,"x");(1,"x");(1,"d");(1,"b");(2,"b");(2,"a");(1,"a")], resultTup)
652660

661+
// float Seq
662+
letminFloat,maxFloat,epsilon= System.Double.MinValue,System.Double.MaxValue,System.Double.Epsilon
663+
letfloatArr=[0.0;0.5;2.0;1.5;1.0; minFloat;maxFloat;epsilon;-epsilon]
664+
letresultFloat= List.sortByDescending id floatArr
665+
letexpectedFloat=[maxFloat;2.0;1.5;1.0;0.5; epsilon;0.0;-epsilon; minFloat;]
666+
Assert.AreEqual(expectedFloat, resultFloat)
667+
653668
()
654669

670+
[<Test>]
671+
memberthis.SortWith()=
672+
673+
// integer list
674+
letintComparer a b= compare(a%3)(b%3)
675+
letresultInt= List.sortWith intComparer[0..10]
676+
Assert.AreEqual([0;3;6;9;1;4;7;10;2;5;8], resultInt)
677+
678+
// string list
679+
letresultStr= List.sortWith compare["str1";"str3";"str2";"str4"]
680+
Assert.AreEqual(["str1";"str2";"str3";"str4"], resultStr)
681+
682+
// empty list
683+
letresultEpt= List.sortWith intComparer[]
684+
Assert.AreEqual([], resultEpt)
685+
686+
()
687+
655688
[<Test>]
656689
memberthis.Sum()=
657690
// empty integer List

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs‎

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,14 +1255,18 @@ type SeqModule2() =
12551255
memberthis.SortDescending()=
12561256

12571257
// integer Seq
1258-
letresultInt= Seq.sortDescending(seq[1;3;2;4;6;5;7])
1259-
letexpectedInt={7..-1..1}
1258+
letresultInt= Seq.sortDescending(seq[1;3;2;Int32.MaxValue;4;6;Int32.MinValue;5;7;0])
1259+
letexpectedInt=seq{
1260+
yield Int32.MaxValue;
1261+
yield!seq{7..-1..0}
1262+
yield Int32.MinValue
1263+
}
12601264
VerifySeqsEqual expectedInt resultInt
12611265

12621266
// string Seq
12631267

1264-
letresultStr=Seq.sortDescending(seq["str1";"str3";"str2";"str4"])
1265-
letexpectedStr= seq["str4";"str3";"str2";"str1"]
1268+
letresultStr=Seq.sortDescending(seq["str1";null;"str3";"";"Str1";"str2";"str4"])
1269+
letexpectedStr= seq["str4";"str3";"str2";"str1";"Str1";"";null]
12661270
VerifySeqsEqual expectedStr resultStr
12671271

12681272
// empty Seq
@@ -1275,6 +1279,13 @@ type SeqModule2() =
12751279
letexpectedTup=(seq[(2,"x");(2,"b");(2,"a");(1,"x");(1,"d");(1,"b");(1,"a")])
12761280
VerifySeqsEqual expectedTup resultTup
12771281

1282+
// float Seq
1283+
letminFloat,maxFloat,epsilon= System.Double.MinValue,System.Double.MaxValue,System.Double.Epsilon
1284+
letfloatSeq= seq[0.0;0.5;2.0;1.5;1.0; minFloat;maxFloat;epsilon;-epsilon]
1285+
letresultFloat= Seq.sortDescending floatSeq
1286+
letexpectedFloat= seq[maxFloat;2.0;1.5;1.0;0.5; epsilon;0.0;-epsilon; minFloat;]
1287+
VerifySeqsEqual expectedFloat resultFloat
1288+
12781289
// null Seq
12791290
CheckThrowsArgumentNullException(fun()-> Seq.sortnull|> ignore)
12801291
()
@@ -1305,10 +1316,39 @@ type SeqModule2() =
13051316
letexpectedTup=(seq[(2,"x");(1,"x");(1,"d");(1,"b");(2,"b");(2,"a");(1,"a")])
13061317
VerifySeqsEqual expectedTup resultTup
13071318

1319+
// float Seq
1320+
letminFloat,maxFloat,epsilon= System.Double.MinValue,System.Double.MaxValue,System.Double.Epsilon
1321+
letfloatSeq= seq[0.0;0.5;2.0;1.5;1.0; minFloat;maxFloat;epsilon;-epsilon]
1322+
letresultFloat= Seq.sortByDescending id floatSeq
1323+
letexpectedFloat= seq[maxFloat;2.0;1.5;1.0;0.5; epsilon;0.0;-epsilon; minFloat;]
1324+
VerifySeqsEqual expectedFloat resultFloat
1325+
13081326
// null Seq
13091327
CheckThrowsArgumentNullException(fun()-> Seq.sortByDescending funcIntnull|> ignore)
13101328
()
13111329

1330+
memberthis.SortWith()=
1331+
1332+
// integer Seq
1333+
letintComparer a b= compare(a%3)(b%3)
1334+
letresultInt= Seq.sortWith intComparer(seq{0..10})
1335+
letexpectedInt= seq[0;3;6;9;1;4;7;10;2;5;8]
1336+
VerifySeqsEqual expectedInt resultInt
1337+
1338+
// string Seq
1339+
letresultStr= Seq.sortWith compare(seq["str1";"str3";"str2";"str4"])
1340+
letexpectedStr= seq["str1";"str2";"str3";"str4"]
1341+
VerifySeqsEqual expectedStr resultStr
1342+
1343+
// empty Seq
1344+
letresultEpt= Seq.sortWith intComparer Seq.empty
1345+
VerifySeqsEqual resultEpt Seq.empty
1346+
1347+
// null Seq
1348+
CheckThrowsArgumentNullException(fun()-> Seq.sortWith intComparernull|> ignore)
1349+
1350+
()
1351+
13121352
[<Test>]
13131353
memberthis.Sum()=
13141354

‎src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1
480480
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] SortByDescending[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T])
481481
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T])
482482
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] SortDescending[T](System.Collections.Generic.IEnumerable`1[T])
483+
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], System.Collections.Generic.IEnumerable`1[T])
483484
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Sort[T](System.Collections.Generic.IEnumerable`1[T])
484485
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Tail[T](System.Collections.Generic.IEnumerable`1[T])
485486
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] TakeWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T])

‎src/fsharp/FSharp.Core.Unittests/SurfaceArea.Portable.fs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Reverse[T](T[])
173173
Microsoft.FSharp.Collections.ArrayModule: T[] Singleton[T](T)
174174
Microsoft.FSharp.Collections.ArrayModule: T[] SkipWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
175175
Microsoft.FSharp.Collections.ArrayModule: T[] Skip[T](Int32, T[])
176+
Microsoft.FSharp.Collections.ArrayModule: T[] SortByDescending[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
176177
Microsoft.FSharp.Collections.ArrayModule: T[] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
178+
Microsoft.FSharp.Collections.ArrayModule: T[] SortDescending[T](T[])
177179
Microsoft.FSharp.Collections.ArrayModule: T[] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], T[])
178180
Microsoft.FSharp.Collections.ArrayModule: T[] Sort[T](T[])
179181
Microsoft.FSharp.Collections.ArrayModule: T[] TakeWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
@@ -328,7 +330,9 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
328330
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Singleton[T](T)
329331
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] SkipWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T])
330332
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Skip[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
333+
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] SortByDescending[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T])
331334
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T])
335+
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] SortDescending[T](Microsoft.FSharp.Collections.FSharpList`1[T])
332336
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], Microsoft.FSharp.Collections.FSharpList`1[T])
333337
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Sort[T](Microsoft.FSharp.Collections.FSharpList`1[T])
334338
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Tail[T](Microsoft.FSharp.Collections.FSharpList`1[T])
@@ -467,7 +471,10 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1
467471
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Singleton[T](T)
468472
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] SkipWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T])
469473
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Skip[T](Int32, System.Collections.Generic.IEnumerable`1[T])
474+
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] SortByDescending[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T])
470475
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T])
476+
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] SortDescending[T](System.Collections.Generic.IEnumerable`1[T])
477+
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], System.Collections.Generic.IEnumerable`1[T])
471478
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Sort[T](System.Collections.Generic.IEnumerable`1[T])
472479
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Tail[T](System.Collections.Generic.IEnumerable`1[T])
473480
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] TakeWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T])

‎src/fsharp/FSharp.Core/array.fs‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -803,17 +803,15 @@ namespace Microsoft.FSharp.Collections
803803
[<CompiledName("SortByDescending")>]
804804
let inlinesortByDescending f array=
805805
checkNonNull"array" array
806-
letresult= copy array
807-
sortInPlaceWith(fun a b-> compare(f b)(f a)) result
808-
result
806+
let inlinecompareDescending a b= compare(f b)(f a)
807+
sortWith compareDescending array
809808

810809
[<CompiledName("SortDescending")>]
811-
let inlinesortDescending array=
810+
let inlinesortDescending array=
812811
checkNonNull"array" array
813-
letresult= copy array
814-
sortInPlaceWith(fun a b-> compare b a) result;
815-
result
816-
812+
let inlinecompareDescending a b= compare b a
813+
sortWith compareDescending array
814+
817815
[<CompiledName("ToSeq")>]
818816
lettoSeq array=
819817
checkNonNull"array" array

‎src/fsharp/FSharp.Core/array.fsi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ namespace Microsoft.FSharp.Collections
800800
///<param name="array">The input array.</param>
801801
///<returns>The sorted array.</returns>
802802
[<CompiledName("SortDescending")>]
803-
val inline sortDescending:array:'T[]-> 'T[]when 'T:comparison
803+
val inline sortDescending:array:'T[]-> 'T[]when 'T:comparison
804804

805805
///<summary>Sorts the elements of an array,in descending order,using the given projection for the keys and returning a new array.
806806
///Elements are compared using Operators.compare.</summary>
@@ -811,7 +811,7 @@ namespace Microsoft.FSharp.Collections
811811
///<param name="array">The input array.</param>
812812
///<returns>The sorted array.</returns>
813813
[<CompiledName("SortByDescending")>]
814-
val inline sortByDescending:projection:('T-> 'Key)->array:'T[]-> 'T[]when 'Key:comparison
814+
val inline sortByDescending:projection:('T-> 'Key)->array:'T[]-> 'T[]when 'Key:comparison
815815

816816
///<summary>Returns the sum of the elements in the array.</summary>
817817
///<param name="array">The input array.</param>

‎src/fsharp/FSharp.Core/list.fs‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,13 @@ namespace Microsoft.FSharp.Collections
482482
|_-> xs
483483

484484
[<CompiledName("SortWith")>]
485-
letsortWith cmp xs= Microsoft.FSharp.Primitives.Basics.List.sortWith cmp xs
485+
letsortWith cmp xs=
486+
match xswith
487+
|[]|[_]-> xs
488+
|_->
489+
letarray= List.toArray xs
490+
Microsoft.FSharp.Primitives.Basics.Array.stableSortInPlaceWith cmp array
491+
List.ofArray array
486492

487493
[<CompiledName("SortBy")>]
488494
letsortBy f xs=
@@ -503,10 +509,14 @@ namespace Microsoft.FSharp.Collections
503509
List.ofArray array
504510

505511
[<CompiledName("SortByDescending")>]
506-
letsortByDescending f xs= Microsoft.FSharp.Primitives.Basics.List.sortByDescending f xs
512+
let inlinesortByDescending f xs=
513+
let inlinecompareDescending a b= compare(f b)(f a)
514+
sortWith compareDescending xs
507515

508516
[<CompiledName("SortDescending")>]
509-
letsortDescending xs= Microsoft.FSharp.Primitives.Basics.List.sortDescending xs
517+
let inlinesortDescending xs=
518+
let inlinecompareDescending a b= compare b a
519+
sortWith compareDescending xs
510520

511521
[<CompiledName("OfSeq")>]
512522
letofSeq source= Seq.toList source

‎src/fsharp/FSharp.Core/list.fsi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,15 +664,15 @@ namespace Microsoft.FSharp.Collections
664664
///<param name="list">The input list.</param>
665665
///<returns>The sorted list.</returns>
666666
[<CompiledName("SortByDescending")>]
667-
val sortByDescending:projection:('T-> 'Key)->list:'T list-> 'T list when 'Key:comparison
667+
valinlinesortByDescending:projection:('T-> 'Key)->list:'T list-> 'T list when 'Key:comparison
668668

669669
///<summary>Sorts the given list in descending order using Operators.compare.</summary>
670670
///
671671
///<remarks>This is a stable sort,i.e. the original order of equal elements is preserved.</remarks>
672672
///<param name="list">The input list.</param>
673673
///<returns>The sorted list.</returns>
674674
[<CompiledName("SortDescending")>]
675-
val sortDescending:list:'T list-> 'T list when 'T:comparison
675+
valinlinesortDescending:list:'T list-> 'T list when 'T:comparison
676676

677677
///<summary>Returns the sum of the elements in the list.</summary>
678678
///<param name="list">The input list.</param>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp