Skip to content

Commit 82759f3

Browse files
xperiandriclaude
andcommitted
fixup! feat: IndexedList and IIndexedList modules with the vocabulary of the FSharp.Core List module
The helpers of the branch get the documentation of `Arrays` and `ParallelArrays`: an explicit `<summary>`, `<param>`, `<returns>`, `<exception>` and `<remarks>` for every function, and `<see cref>` instead of `<c>` for every function and type of FSharp.Core. The remarks say why the function exists. - `ListChecks`: every check names the functions of `List` that it serves, the exception that it throws (the type, the message and the parameter name) and, where a sibling check exists, why the two are separate (`item` and `removeAt` differ in the message, `replicate` and `nonNegative` in the value, `exists2` and `sameLengths` in the names, `zip3` and `map3` in the lengths, `notEmpty` and `notEmptySequence` in the word). `foldBack2` says why it has two branches, and `transpose` which pair of lists it reports, checked against `local.fs` of FSharp.Core. The private literal `IndexOutsideListBounds` says which five functions of `List` write it and why it is not in `ErrorStrings`. - `ListArrays`: the summaries, the descriptions of the parameters and of the results are those of the functions of `List`. Each remark says why the function is not `Array.iter2` and its siblings: they compare the lengths before they call the callback and report arrays, where the functions of `List` call the callback for the common prefix first and report lists. - `Snapshot`, `Lengths` (with its private `countUpTo`), `DescendingSorts` and `ListRanges`: parameters, results and exceptions, the reason for each function, and the functions that call it. The private literal of `ListRanges` said that its message is the one of System.Collections.Immutable; no resource of that assembly holds it. The runtime throws the message from ``List`1.BinarySearch`` with "array" and "source collection", and the literal says "list", so the comment says that. - The three functions that the branch adds to `Raise` (`invalidArg2ListsDifferent`, `invalidArgRandomizerOutOfRange` and `invalidOpListEmpty`) replace one-line comments with backticks. No code changed: without the doc comments, every file is identical to the file before. The build with `--warnon:3390`, `dotnet fantomas --check` and a check of every `cref` against the generated XML documentation, FSharp.Core and the reference assemblies are clean. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent d416a34 commit 82759f3

7 files changed

Lines changed: 766 additions & 96 deletions

File tree

‎src/FSharp.Collections.Immutable/Helper/DescendingSorts.fs‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// <summary>
2-
/// The descending sorts of the modules that mirror <c>List</c>: the stable sorts of FSharp.Core, with the comparison of
3-
/// F# generic comparison that the type caches, and without the boxes of the inline sorts of <c>Seq</c> (ADR 0001, D5).
2+
/// The descending sorts of the modules that mirror <see cref="T:Microsoft.FSharp.Collections.ListModule"/>: stable sorts
3+
/// in the order of F# generic comparison, with the comparer that the type caches, and without the boxes of the inline
4+
/// sorts of <see cref="T:Microsoft.FSharp.Collections.SeqModule"/> (ADR 0001, D5).
45
/// </summary>
56
/// <remarks>
67
/// <para>
@@ -13,7 +14,7 @@
1314
/// <para>
1415
/// The sorts here call
1516
/// <see cref="M:Microsoft.FSharp.Collections.SeqModule.SortWith``1(Microsoft.FSharp.Core.FSharpFunc{``0,Microsoft.FSharp.Core.FSharpFunc{``0,System.Int32}},System.Collections.Generic.IEnumerable{``0})"/>,
16-
/// which is not inline and runs the stable sort of <c>List</c>, with the comparer that
17+
/// which is not inline and runs the stable sort of <see cref="T:Microsoft.FSharp.Collections.ListModule"/>, with the comparer that
1718
/// <see cref="T:FSharp.Collections.Immutable.Comparers.DefaultComparer`1"/> caches for the type. The comparer compares
1819
/// as the generic operator does, so the comparisons, their order and the exceptions that they throw are those of
1920
/// <see cref="M:Microsoft.FSharp.Collections.ListModule.SortDescending``1(Microsoft.FSharp.Collections.FSharpList{``0})"/>
@@ -32,8 +33,18 @@ module internal FSharp.Collections.Immutable.DescendingSorts
3233
/// <param name="source">The elements, which the caller has checked for <see langword="null"/>.</param>
3334
/// <returns>The elements, equal elements in their order.</returns>
3435
/// <remarks>
35-
/// The comparer compares the second element with the first, as <c>List.sortDescending</c> does. The sort allocates
36-
/// the arrays of FSharp.Core and nothing per comparison, for a type that has a primitive comparer.
36+
/// <para>
37+
/// The comparer compares the second element with the first, as
38+
/// <see cref="M:Microsoft.FSharp.Collections.ListModule.SortDescending``1(Microsoft.FSharp.Collections.FSharpList{``0})"/>
39+
/// does. The sort allocates the arrays
40+
/// of FSharp.Core and nothing per comparison, for a type that has a primitive comparer.
41+
/// </para>
42+
/// <para>
43+
/// It exists instead of
44+
/// <see cref="M:Microsoft.FSharp.Collections.SeqModule.SortDescending``1(System.Collections.Generic.IEnumerable{``0})"/>,
45+
/// which boxes the elements of a value type in every comparison (see the
46+
/// remarks of the module).
47+
/// </para>
3748
/// </remarks>
3849
let sortDescending (source : seq<'T>) =
3950
let comparer = DefaultComparer<'T>.Instance
@@ -49,8 +60,17 @@ let sortDescending (source : seq<'T>) =
4960
/// <param name="source">The elements, which the caller has checked for <see langword="null"/>.</param>
5061
/// <returns>The elements, those with equal keys in their order.</returns>
5162
/// <remarks>
63+
/// <para>
5264
/// The projection runs in the comparison, twice for each comparison and for the second element first, as it does in
53-
/// <c>List.sortByDescending</c>; the keys are not computed beforehand.
65+
/// <see cref="M:Microsoft.FSharp.Collections.ListModule.SortByDescending``2(Microsoft.FSharp.Core.FSharpFunc{``0,``1},Microsoft.FSharp.Collections.FSharpList{``0})"/>;
66+
/// the keys are not computed beforehand.
67+
/// </para>
68+
/// <para>
69+
/// It exists instead of
70+
/// <see cref="M:Microsoft.FSharp.Collections.SeqModule.SortByDescending``2(Microsoft.FSharp.Core.FSharpFunc{``0,``1},System.Collections.Generic.IEnumerable{``0})"/>,
71+
/// which boxes the keys of a value type in every comparison (see the remarks
72+
/// of the module).
73+
/// </para>
5474
/// </remarks>
5575
let sortByDescending (projection : 'T -> 'Key) (source : seq<'T>) =
5676
let comparer = DefaultComparer<'Key>.Instance

‎src/FSharp.Collections.Immutable/Helper/Lengths.fs‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
/// </summary>
66
/// <remarks>
77
/// <para>
8-
/// The checks of <c>ListChecks</c> take a length, but most of them only tell an empty input from one with elements, or an
9-
/// input of one element from a longer one, and the sorts return an input of at most one element unchanged. A count of a
10-
/// whole queue or stack would make each of them O(n).
8+
/// The checks of <see cref="T:FSharp.Collections.Immutable.ListChecks"/> take a length, but most of them only tell an empty
9+
/// input from one with elements, or an input of one element from a longer one, and the sorts return an input of at most one
10+
/// element unchanged. A count of a whole queue or stack would make each of them O(n).
1111
/// </para>
1212
/// <para>
1313
/// The modules of the queues and the stacks pass a limit instead: 1 to tell an empty input from one with elements, 2 to
@@ -19,8 +19,25 @@ module internal FSharp.Collections.Immutable.Lengths
1919

2020
open System.Collections.Immutable
2121

22-
/// Counts the elements up to the limit, stepping from a collection to the collection without its first element. The step
23-
/// runs at most limit - 1 times, so a limit of 1 only reads whether the collection is empty.
22+
/// <summary>
23+
/// Counts the elements of a collection up to a limit, by stepping from the collection to the collection without its first
24+
/// element.
25+
/// </summary>
26+
/// <param name="isEmpty">Tells whether a collection has no element.</param>
27+
/// <param name="rest">Returns the collection without its first element; the collection is not empty.</param>
28+
/// <param name="limit">The largest number to count.</param>
29+
/// <param name="collection">The collection to count.</param>
30+
/// <returns>The smaller of the number of elements and the limit, and 0 for a limit that is not positive.</returns>
31+
/// <remarks>
32+
/// <para>
33+
/// The step runs at most limit - 1 times, so a limit of 1 only reads whether the collection is empty.
34+
/// </para>
35+
/// <para>
36+
/// The queue and the stack differ only in how they tell that no element is left and how they step, so the loop exists
37+
/// once. It is inline and inlines its two functions, so that a count contains the calls of the interface members
38+
/// themselves, not calls of closures.
39+
/// </para>
40+
/// </remarks>
2441
let inline private countUpTo
2542
([<InlineIfLambda>] isEmpty : 'Collection -> bool)
2643
([<InlineIfLambda>] rest : 'Collection -> 'Collection)

0 commit comments

Comments
 (0)