Skip to content

The documention about maxBy (Array, List, ...) should state that the first max value is returned. #19129

Closed

Description

@ursenzler

Consider this code: myArray |> Array.indexed |> Array.maxBy snd |> fst

The code returns the index of the first max value. However, the documentation does not state this fact. I had to look into the implementation (I looked into the implementation of Array).

I propose to add this fact to the according documentatation pages (e.g. https://fsharp.github.io/fsharp-core-docs/reference/fsharp-collections-arraymodule.html#maxBy).

I can provide a PR, but I want to check first, whether it would have a chance to be accepted - maybe there is no such guarantee of returning the first maximum.

Activity

  1. added this to the Backlog milestone on Dec 3, 2025
  2. added
    Area-Library
    and removed on Dec 3, 2025
  3. T-Gro commented on Dec 3, 2025

    @T-Gro
    Member

    This will be accepted 👍 , thank you for spotting this.
    maxBy for List/Array/Seq shall have it. The one for Query should not as we do not control the underlying implementations.

    https://github.com/search?q=repo%3Adotnet%2Ffsharp+maxBy+path%3A%2F%5Esrc%5C%2FFSharp%5C.Core%5C%2F%2F&type=code

    This could be also added as a special case for existing maxBy tests in order to guard that behavior for future regressions (e.g. if anyone would want to change implementation of the functions in the future) - https://github.com/search?q=repo%3Adotnet%2Ffsharp+maxBy+path%3A%2F%5Etests%5C%2FFSharp%5C.Core%5C.UnitTests%5C%2FFSharp%5C.Core%5C%2FMicrosoft%5C.FSharp%5C.Collections%5C%2F%2F&type=code . CollectionsModulesConsistency will allow to write a test to guard the three major collection types via an unified test.

  4. ursenzler commented on Dec 5, 2025

    @ursenzler
    Author

    See PR #19140

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-DocumentationArea-Librarygood first issue

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions