diff --git a/src/FSharp.Core/array.fsi b/src/FSharp.Core/array.fsi index 65def57f048..94fde103a88 100644 --- a/src/FSharp.Core/array.fsi +++ b/src/FSharp.Core/array.fsi @@ -1789,7 +1789,7 @@ module Array = /// Returns the greatest of all elements of the array, compared via Operators.max on the function result. /// - /// Throws ArgumentException for empty arrays. + /// Returns the first maximal element of the array if there are multiple equal maximum elements. /// /// The function to transform the elements into a type supporting comparison. /// The input array. @@ -1852,8 +1852,8 @@ module Array = /// Returns the lowest of all elements of the array, compared via Operators.min on the function result. /// - /// Throws ArgumentException for empty arrays. - /// + /// Returns the first minimal element of the array if there are multiple equal minimal elements. + /// /// The function to transform the elements into a type supporting comparison. /// The input array. /// diff --git a/src/FSharp.Core/list.fsi b/src/FSharp.Core/list.fsi index 1b48f6d9c60..98f129dbc93 100644 --- a/src/FSharp.Core/list.fsi +++ b/src/FSharp.Core/list.fsi @@ -1479,7 +1479,8 @@ module List = /// Returns the greatest of all elements of the list, compared via Operators.max on the function result. /// - /// Raises if list is empty. + /// Returns the first maximal element of the list if there are multiple equal maximum elements. + /// /// The function to transform the list elements into the type to be compared. /// The input list. /// @@ -1538,7 +1539,8 @@ module List = /// Returns the lowest of all elements of the list, compared via Operators.min on the function result /// - /// Raises if list is empty. + /// Returns the first minimal element of the list if there are multiple equal minimal elements. + /// /// The function to transform list elements into the type to be compared. /// The input list. /// diff --git a/src/FSharp.Core/seq.fsi b/src/FSharp.Core/seq.fsi index 8aedfa6ff6d..4f121e92ee4 100644 --- a/src/FSharp.Core/seq.fsi +++ b/src/FSharp.Core/seq.fsi @@ -1716,6 +1716,8 @@ module Seq = /// Returns the greatest of all elements of the sequence, compared via Operators.max on the function result. /// + /// Returns the first maximal element of the sequence if there are multiple equal maximum elements. + /// /// A function to transform items from the input sequence into comparable keys. /// The input sequence. /// @@ -1780,6 +1782,8 @@ module Seq = /// /// The smallest element of the sequence. /// + /// Returns the first minimal element of the sequence if there are multiple equal minimal elements. + /// /// Thrown when the input sequence is null. /// Thrown when the input sequence is empty. /// diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule2.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule2.fs index b0532b8929f..a7bd6c05cc9 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule2.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule2.fs @@ -304,6 +304,10 @@ type ArrayModule2() = // len = 0 CheckThrowsArgumentException(fun() -> Array.maxBy funcInt (Array.empty) |> ignore) + // returns first maximal element + let max = Array.maxBy fst [|1, "a"; 2, "b"; 3, "c"; 2, "d"; 3, "e"; 1, "f" |] + if snd max <> "c" then Assert.Fail() + () [] @@ -348,6 +352,10 @@ type ArrayModule2() = // len = 0 CheckThrowsArgumentException(fun () -> Array.minBy funcInt (Array.empty) |> ignore) + // returns first minimal element + let max = Array.minBy fst [|3, "a"; 2, "b"; 1, "c"; 2, "d"; 1, "e"; 3, "f" |] + if snd max <> "c" then Assert.Fail() + () diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs index 3a27d4e7d2a..03a71739823 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs @@ -291,6 +291,10 @@ type ListModule02() = // empty List CheckThrowsArgumentException ( fun() -> List.maxBy (fun () -> 1) List.empty ) + // returns first maximal element + let max = List.maxBy fst [1, "a"; 2, "b"; 3, "c"; 2, "d"; 3, "e"; 1, "f" ] + if snd max <> "c" then Assert.Fail() + () [] @@ -324,6 +328,10 @@ type ListModule02() = let funcEpt () = 1 CheckThrowsArgumentException ( fun() -> List.minBy funcEpt List.empty) + // returns first minimal element + let max = List.minBy fst [ 3, "a"; 2, "b"; 1, "c"; 2, "d"; 1, "e"; 3, "f" ] + if snd max <> "c" then Assert.Fail() + () [] diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs index db3b8a3adcc..bef4ddbb51f 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs @@ -969,6 +969,10 @@ type SeqModule2() = let nullSeq:seq<'a> = null CheckThrowsArgumentNullException (fun () ->Seq.maxBy funcInt nullSeq |> ignore) + // returns first maximal element + let max = Seq.maxBy fst (seq { 1, "a"; 2, "b"; 3, "c"; 2, "d"; 3, "e"; 1, "f" }) + if snd max <> "c" then Assert.Fail() + () [] @@ -991,6 +995,10 @@ type SeqModule2() = let nullSeq:seq<'a> = null CheckThrowsArgumentNullException (fun () ->Seq.minBy funcInt nullSeq |> ignore) + // returns first minimal element + let max = Seq.minBy fst (seq { 3, "a"; 2, "b"; 1, "c"; 2, "d"; 1, "e"; 3, "f" }) + if snd max <> "c" then Assert.Fail() + ()