Repository navigation
feat: HashMap and IMap modules with the vocabulary of the FSharp.Core Map module - #30
Open
xperiandri wants to merge 18 commits into
Open
xperiandri wants to merge 18 commits into
xperiandri wants to merge 18 commits into
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
The broad breaking API rewrite and comparer-sensitive behavior warrant human compatibility review and validation across both target frameworks.
No open issues 🎉
What changed in this PR
Rewrites HashMap and introduces IMap using FSharp.Core Map vocabulary, continuing the per-collection architecture established by ADR 0001.
Changes:
- Adds map operations, shared dictionary algorithms, Option/Tuple variants, and
hashMapcomputation expressions. - Adds reusable map contracts and collection-specific tests.
- Updates documentation and migration notes for breaking API changes.
| File | Description |
|---|---|
| tests/FSharp.Collections.Immutable.Tests/HashMap/IMapTupleTests.fs | Tests reference-tuple overrides. |
| tests/FSharp.Collections.Immutable.Tests/HashMap/IMapTests.fs | Tests interface behavior and comparers. |
| tests/FSharp.Collections.Immutable.Tests/HashMap/IMapOptionTests.fs | Tests option overrides. |
| tests/FSharp.Collections.Immutable.Tests/HashMap/IMapOps.fs | Supplies interface contract operations. |
| tests/FSharp.Collections.Immutable.Tests/HashMap/IMapContractTests.fs | Instantiates interface contracts. |
| tests/FSharp.Collections.Immutable.Tests/HashMap/HashMapTupleTests.fs | Tests reference-tuple overrides. |
| tests/FSharp.Collections.Immutable.Tests/HashMap/HashMapTests.fs | Tests hash-map-specific behavior. |
| tests/FSharp.Collections.Immutable.Tests/HashMap/HashMapOptionTests.fs | Tests option overrides. |
| tests/FSharp.Collections.Immutable.Tests/HashMap/HashMapOps.fs | Supplies hash-map contract operations. |
| tests/FSharp.Collections.Immutable.Tests/HashMap/HashMapContractTests.fs | Instantiates hash-map contracts. |
| tests/FSharp.Collections.Immutable.Tests/HashMap/HashMapComputationExpressionTests.fs | Tests expression construction and control flow. |
| tests/FSharp.Collections.Immutable.Tests/HashMap/HashMapBuilderTests.fs | Tests builder behavior. |
| tests/FSharp.Collections.Immutable.Tests/FSharp.Collections.Immutable.Tests.fsproj | Registers new tests and contracts. |
| tests/FSharp.Collections.Immutable.Tests/Contracts/MapTransformContract.fs | Adds shared transformation tests. |
| tests/FSharp.Collections.Immutable.Tests/Contracts/MapOps.fs | Defines contract inputs and operations. |
| tests/FSharp.Collections.Immutable.Tests/Contracts/MapMutationContract.fs | Adds shared mutation tests. |
| tests/FSharp.Collections.Immutable.Tests/Contracts/MapCreationContract.fs | Adds shared creation tests. |
| tests/FSharp.Collections.Immutable.Tests/Contracts/MapContract.fs | Adds reading, ordering, and exception contracts. |
| src/FSharp.Collections.Immutable/Maps.fs | Removes legacy hash-map definitions. |
| src/FSharp.Collections.Immutable/Helper.fs | Adds shared dictionary algorithms and exceptions. |
| src/FSharp.Collections.Immutable/HashMap/IMapTuple.fsi | Declares reference-tuple interface API. |
| src/FSharp.Collections.Immutable/HashMap/IMapTuple.fs | Implements reference-tuple interface operations. |
| src/FSharp.Collections.Immutable/HashMap/IMapOption.fsi | Declares option-based interface API. |
| src/FSharp.Collections.Immutable/HashMap/IMapOption.fs | Implements interface option adapters. |
| src/FSharp.Collections.Immutable/HashMap/IMap.fsi | Documents the interface map API. |
| src/FSharp.Collections.Immutable/HashMap/IMap.fs | Implements interface map operations. |
| src/FSharp.Collections.Immutable/HashMap/HashMapTuple.fsi | Declares reference-tuple hash-map API. |
| src/FSharp.Collections.Immutable/HashMap/HashMapTuple.fs | Implements reference-tuple hash-map operations. |
| src/FSharp.Collections.Immutable/HashMap/HashMapOption.fsi | Declares option-based hash-map API. |
| src/FSharp.Collections.Immutable/HashMap/HashMapOption.fs | Implements hash-map option adapters. |
| src/FSharp.Collections.Immutable/HashMap/HashMapCE.fs | Adds the hash-map expression builder. |
| src/FSharp.Collections.Immutable/HashMap/HashMap.fs | Implements the rewritten hash-map operations. |
| src/FSharp.Collections.Immutable/FSharp.Collections.Immutable.fsproj | Registers new library files. |
| src/FSharp.Collections.Immutable/ComputationExpressions.fs | Exposes the hashMap expression. |
| README.md | Lists interface and expression support. |
| docsSrc/Tutorials/Getting_Started.md | Updates construction to struct tuples. |
| docsSrc/index.md | Updates the collection overview. |
| docsSrc/Explanations/Background.md | Updates the collection support table. |
| CHANGELOG.md | Records additions and breaking changes. |
Review effort: Balanced
xperiandri
commented
Oct 18, 2026
xperiandri
added a commit
that referenced
this pull request
Oct 18, 2026
…in ADR 0001 The review of the HashMap pull request (#30) changes three parts of the design: - D2: a file with one module declares it as the root module of the file; the type abbreviations of a folder move to `XTypes.fsi`/`XTypes.fs`, because a root module cannot declare a type of its namespace. Modules carry no `[<CompiledName>]`. - D12 (new): the comparers that a map or a set keeps come only through one `Comparable*` struct per collection, whose members are the creation functions with the comparers applied. It replaces the `*WithComparer(s)`, `*WithKeyComparer` and `with*Comparer(s)` functions. - D13 (new): `ofArray`, `ofList` and `ofSeq` of the maps are static extension members in an `[<AutoOpen>]` `XExtensions` module, overloaded for `KeyValuePair`, reference tuples and struct tuples. `ofKeyValuePairs` and the `Tuple` creation functions go; `setItems` takes struct tuples like `addRange`. The ADR also records what the implementation found: the explicit type parameters of the alternate lookups (FS0687), the `comparison` constraint and the cached default comparer of the sorted collections, the O(n) `maxKeyValue` of `SortedMap`, and why `keys`/`values` return different types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 of 6 tasks
xperiandri
added a commit
that referenced
this pull request
Oct 18, 2026
…in ADR 0001 The review of the HashMap pull request (#30) changes three parts of the design: - D2: a file with one module declares it as the root module of the file; the type abbreviations of a folder move to `XTypes.fsi`/`XTypes.fs`, because a root module cannot declare a type of its namespace. Modules carry no `[<CompiledName>]`. - D12 (new): the comparers that a map or a set keeps come only through one `Comparable*` struct per collection, whose members are the creation functions with the comparers applied. It replaces the `*WithComparer(s)`, `*WithKeyComparer` and `with*Comparer(s)` functions. - D13 (new): `ofArray`, `ofList` and `ofSeq` of the maps are static extension members in an `[<AutoOpen>]` `XExtensions` module, overloaded for `KeyValuePair`, reference tuples and struct tuples. `ofKeyValuePairs` and the `Tuple` creation functions go; `setItems` takes struct tuples like `addRange`. The ADR also records what the implementation found: the explicit type parameters of the alternate lookups (FS0687), the `comparison` constraint and the cached default comparer of the sorted collections, the O(n) `maxKeyValue` of `SortedMap`, and why `keys`/`values` return different types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xperiandri
force-pushed
the
feat/hash-map
branch
from
October 18, 2026 13:03
309a2c0 to
3ff05d9
Compare
xperiandri
force-pushed
the
feat/flat-list
branch
2 times, most recently
from
October 18, 2026 15:35
2b5179a to
9d2526e
Compare
xperiandri
force-pushed
the
feat/hash-map
branch
from
October 18, 2026 15:35
3ff05d9 to
3f22fda
Compare
This was referenced Oct 18, 2026
xperiandri
force-pushed
the
feat/flat-list
branch
from
October 18, 2026 18:44
9d2526e to
047ee9b
Compare
xperiandri
added a commit
that referenced
this pull request
Oct 18, 2026
…FSharp.Core `Map` module Follows the reworked ADR 0001 (D2, D12, D13) and the review of #30: - `HashMap`, `IMap` and their `Option` and `Tuple` modules are the root modules of their files. The `HashMap` and `IMap` abbreviations move to `HashMap/HashMapTypes.fs`. - `CustomComparersHashMap<'Key, 'Value>` holds the key comparer and the value comparer, or the key comparer and the default value comparer, and creates hash maps with them through the members `empty`, `singleton`, `ofArray`, `ofList`, `ofSeq`, `ofSeqBy` and `builder`. A `null` comparer throws `ArgumentNullException` with the name of its parameter, and the default value of the struct stands for the default comparers. `ofSeq` gives an existing map the comparers of the struct, without a copy when the key comparer stays. - `HashMap.forComparers` and `HashMap.forKeyComparer` create the struct. They replace `emptyWithComparers`, `emptyWithKeyComparer`, `ofKeyValuePairsWithKeyComparer`, `ofSeqWithKeyComparer`, `builderWithComparers`, `builderWithKeyComparer`, `withComparers` and `withKeyComparer`. - `HashMapExtensions` extends `ImmutableDictionary<'Key, 'Value>` with static `ofArray`, `ofList` and `ofSeq`, each overloaded for `KeyValuePair`s, reference tuples and struct tuples: the members of the struct with the default comparers. The module loses `ofArray`, `ofList`, `ofSeq` and `ofKeyValuePairs`, so that `HashMap.ofSeq pairs` reaches the overloads, also in a pipeline. Every shape keeps the last binding of a key, as `Map.ofSeq` does. - `addRange` of `HashMap` and `IMap` takes `KeyValuePair`s, as `setItems` does; the nested modules `Tuple` and `ValueTuple` hold both functions for reference and struct tuples. The modules of the `Tuple` namespace keep `partition`, `toArray`, `toList` and `toSeq`. - `Dictionaries` in `Helper.fs` gets the deconstructors of the binding shapes, `splitKeyValuePair` and `splitTuple`, for every map module and comparer struct. - `HashMapCE` rejects a `null` key comparer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xperiandri
force-pushed
the
feat/hash-map
branch
from
October 18, 2026 18:47
3f22fda to
8d763b8
Compare
xperiandri
added a commit
that referenced
this pull request
Oct 18, 2026
…FSharp.Core `Map` module Follows the reworked ADR 0001 (D2, D12, D13) and the review of #30: - `HashMap`, `IMap` and their `Option` and `Tuple` modules are the root modules of their files. The `HashMap` and `IMap` abbreviations move to `HashMap/HashMapTypes.fs`. - `CustomComparersHashMap<'Key, 'Value>` holds the key comparer and the value comparer, or the key comparer and the default value comparer, and creates hash maps with them through the members `empty`, `singleton`, `ofArray`, `ofList`, `ofSeq`, `ofSeqBy` and `builder`. A `null` comparer throws `ArgumentNullException` with the name of its parameter, and the default value of the struct stands for the default comparers. `ofSeq` gives an existing map the comparers of the struct, without a copy when the key comparer stays. - `HashMap.forComparers` and `HashMap.forKeyComparer` create the struct. They replace `emptyWithComparers`, `emptyWithKeyComparer`, `ofKeyValuePairsWithKeyComparer`, `ofSeqWithKeyComparer`, `builderWithComparers`, `builderWithKeyComparer`, `withComparers` and `withKeyComparer`. - `HashMapExtensions` extends `ImmutableDictionary<'Key, 'Value>` with static `ofArray`, `ofList` and `ofSeq`, each overloaded for `KeyValuePair`s, reference tuples and struct tuples: the members of the struct with the default comparers. The module loses `ofArray`, `ofList`, `ofSeq` and `ofKeyValuePairs`, so that `HashMap.ofSeq pairs` reaches the overloads, also in a pipeline. Every shape keeps the last binding of a key, as `Map.ofSeq` does. - `addRange` of `HashMap` and `IMap` takes `KeyValuePair`s, as `setItems` does; the nested modules `Tuple` and `ValueTuple` hold both functions for reference and struct tuples. The modules of the `Tuple` namespace keep `partition`, `toArray`, `toList` and `toSeq`. - `Dictionaries` in `Helper.fs` gets the deconstructors of the binding shapes, `splitKeyValuePair` and `splitTuple`, for every map module and comparer struct. - `HashMapCE` rejects a `null` key comparer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xperiandri
force-pushed
the
feat/hash-map
branch
from
October 18, 2026 20:11
8d763b8 to
ed2f285
Compare
xperiandri
added a commit
that referenced
this pull request
Oct 18, 2026
…FSharp.Core `Map` module Follows the reworked ADR 0001 (D2, D12, D13) and the review of #30: - `HashMap`, `IMap` and their `Option` and `Tuple` modules are the root modules of their files. The `HashMap` and `IMap` abbreviations move to `HashMap/HashMapTypes.fs`. - `CustomComparersHashMap<'Key, 'Value>` holds the key comparer and the value comparer, or the key comparer and the default value comparer, and creates hash maps with them through the members `empty`, `singleton`, `ofArray`, `ofList`, `ofSeq`, `ofSeqBy` and `builder`. A `null` comparer throws `ArgumentNullException` with the name of its parameter, and the default value of the struct stands for the default comparers. `ofSeq` gives an existing map the comparers of the struct, without a copy when the key comparer stays. - `HashMap.forComparers` and `HashMap.forKeyComparer` create the struct. They replace `emptyWithComparers`, `emptyWithKeyComparer`, `ofKeyValuePairsWithKeyComparer`, `ofSeqWithKeyComparer`, `builderWithComparers`, `builderWithKeyComparer`, `withComparers` and `withKeyComparer`. - `HashMapExtensions` extends `ImmutableDictionary<'Key, 'Value>` with static `ofArray`, `ofList` and `ofSeq`, each overloaded for `KeyValuePair`s, reference tuples and struct tuples: the members of the struct with the default comparers. The module loses `ofArray`, `ofList`, `ofSeq` and `ofKeyValuePairs`, so that `HashMap.ofSeq pairs` reaches the overloads, also in a pipeline. Every shape keeps the last binding of a key, as `Map.ofSeq` does. - `addRange` of `HashMap` and `IMap` takes `KeyValuePair`s, as `setItems` does; the nested modules `Tuple` and `ValueTuple` hold both functions for reference and struct tuples. The modules of the `Tuple` namespace keep `partition`, `toArray`, `toList` and `toSeq`. - `Dictionaries` in `Helper.fs` gets the deconstructors of the binding shapes, `splitKeyValuePair` and `splitTuple`, for every map module and comparer struct. - `HashMapCE` rejects a `null` key comparer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xperiandri
force-pushed
the
feat/hash-map
branch
from
October 18, 2026 22:36
d61c19f to
0e1a08a
Compare
- `MapOps`, `MapTransformOps`, `MapMutationOps` and `MapCreationOps` record the functions of a map module, and `MapContract`, `MapTransformContract`, `MapMutationContract` and `MapCreationContract` are the facets on `MapContractBase`. - Expected values come from the FSharp.Core `Map` module and compare as bindings sorted by key, because a hash map enumerates in an unspecified order; the functions that visit the bindings one by one are checked against the order in which the map enumerates them. - Expected exceptions come from `Map` through `ExceptionAssert.same`, so `Mirror` stays about the sequence-like modules. - `HashMap` derives all four facets and `IMap` all but the creation one, over hash maps. Their own tests cover null inputs, comparers, results that share the input, the builder functions, the computation expression and the `Option` and `Tuple` namespaces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the tutorial The tutorial creates its hash map from struct tuples, which `HashMap.ofSeq` takes now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ll the default modules by their short names Each of these files opens `FSharp.Collections.Immutable`, and inside `FSharp.Collections.Immutable.Tuple.HashMap` the name `HashMap` reaches the default module, also for the functions that both modules define, so the full namespace in front of it added nothing. The compiled code is the same: the opcodes and the called methods of every method of both builds match one to one. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nd `IMap` A documentation comment with a tag starts with an explicit `<summary>` (the project instructions): the compiler escapes the tags of a comment that has no `<summary>`. The two cases of `MapImplementation`, the two cases of `SpanCreation` and `MapInputs.RepeatedKeys` had comments with `<see>` or `<c>` and no `<summary>`. The tests check the size of a collection with `Assert.HasCount`, `Assert.IsEmpty` and `Assert.ContainsSingle`, as the instructions ask, and not with `Assert.AreEqual` of its count. The 13 assertions are in the tests of the builders, of the creation with comparers, of the computation expression, of `HashMap` and of `IMap`; they report the bindings when they fail. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…FSharp.Core `Map` module The helpers of the branch get the documentation of `Arrays` and `ParallelArrays` (the review of #40 and #31): an explicit `<summary>`, `<param>`, `<returns>` and `<remarks>` for every function, `<see cref>` for every function of FSharp.Core, and a remark that says why the function exists. - `Dictionaries`: the summaries, the descriptions of the parameters and of the results are those of the functions of the FSharp.Core `Map` module where the signatures agree. Each remark says what differs: the FSharp.Core function takes an F# map, the bindings here are the pairs of a dictionary of the BCL, `tryFindKey` and `tryPick` use value options, `foldBack` copies the bindings because an enumerator moves only forwards, `choose`, `map`, `filter` and `partition` fill a target that the caller creates with the comparers it wants, and `toArray`, `toList` and `toSeq` take the constructor of the tuples, for the default and the `Tuple` modules. `setAll` says that the indexer keeps the stored binding for a value that the value comparer finds equal (ADR 0001, D14). `choose`, `splitKeyValuePair`, `splitTuple`, `setAll` and `toKeyValuePairs` say that FSharp.Core has no such function. - `Raise.keyNotFound`: the exception, the result and the difference from `indexNotFound`. No code changed: without the doc comments, both files are identical to the files before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…FSharp.Core `Map` module The signature documentation refers to the functions and the types of FSharp.Core, of the BCL and of the library with `<see cref>`, not with `<c>` (the review of #31): `Map.add` (six places), `ImmutableInterlocked` and `ImmutableInterlocked.TryAdd` in `HashMap.fsi`, and `HashMap.tryFind` and `IMap.tryFind`. The names that stay in `<c>` are the code samples, the compiled names of the extension members, and the names of the overloaded families `ofArray`, `ofList` and `ofSeq`, which have no single member to refer to. No code changed: without the doc comments, both files are identical to the files before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nd `IMap` The comments that got an explicit `<summary>` in the previous fixup refer to the functions, the properties and the types of FSharp.Core, of the BCL and of the library with `<see cref>`, not with `<c>` (the project instructions, the review of #31 and the review of CodeRabbit on #30). The `<c>` that stay name code samples and the types of the test project, which have no documentation file to refer to. No code changed: without the doc comments, the files are identical to the files before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…FSharp.Core `Map` module The remarks of `Dictionaries.choose` and `Dictionaries.map` said that the keys keep the comparer of the input. That holds for `HashMap.choose` and `HashMap.map`, which create the target with `KeyComparer` of the table. `IMap.choose` and `IMap.map` cannot read the key comparer through the interface and create the target with the default one. The remarks now say so. No code changed: without the doc comments, the file is identical to the file before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…FSharp.Core `Map` module
xperiandri
force-pushed
the
feat/hash-map
branch
from
November 15, 2026 00:59
f452567 to
2dfacfc
Compare
Irina-Konovalova
approved these changes
Nov 17, 2026
VectorTetra
approved these changes
Nov 18, 2026
xperiandri
added a commit
that referenced
this pull request
Nov 18, 2026
…nd `IMap` The comments that got an explicit `<summary>` in the previous fixup refer to the functions, the properties and the types of FSharp.Core, of the BCL and of the library with `<see cref>`, not with `<c>` (the project instructions, the review of #31 and the review of CodeRabbit on #30). The `<c>` that stay name code samples and the types of the test project, which have no documentation file to refer to. No code changed: without the doc comments, the files are identical to the files before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
xperiandri
added a commit
that referenced
this pull request
Nov 18, 2026
…nd `ISet` The comments that got an explicit `<summary>` in the previous fixup refer to the functions, the properties and the types of FSharp.Core, of the BCL and of the library with `<see cref>`, not with `<c>` (the project instructions, the review of #31 and the review of CodeRabbit on #30). The `<c>` that stay name code samples and the types of the test project, which have no documentation file to refer to. No code changed: without the doc comments, the files are identical to the files before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
xperiandri
force-pushed
the
feat/hash-map
branch
from
November 18, 2026 14:17
2dfacfc to
97d18b8
Compare
xperiandri
added a commit
that referenced
this pull request
Nov 18, 2026
…Map` The comments that got an explicit `<summary>` in the previous fixup refer to the functions, the properties and the types of FSharp.Core, of the BCL and of the library with `<see cref>`, not with `<c>` (the project instructions, the review of #31 and the review of CodeRabbit on #30). The `<c>` that stay name code samples and the types of the test project, which have no documentation file to refer to. No code changed: without the doc comments, the files are identical to the files before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
xperiandri
added a commit
that referenced
this pull request
Nov 18, 2026
…Set` The comments that got an explicit `<summary>` in the previous fixup refer to the functions, the properties and the types of FSharp.Core, of the BCL and of the library with `<see cref>`, not with `<c>` (the project instructions, the review of #31 and the review of CodeRabbit on #30). The `<c>` that stay name code samples and the types of the test project, which have no documentation file to refer to. No code changed: without the doc comments, the files are identical to the files before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
xperiandri
force-pushed
the
feat/hash-map
branch
from
November 18, 2026 18:50
97d18b8 to
03a7990
Compare
xperiandri
added a commit
that referenced
this pull request
Nov 18, 2026
…in ADR 0001 The review of the HashMap pull request (#30) changes three parts of the design: - D2: a file with one module declares it as the root module of the file; the type abbreviations of a folder move to `XTypes.fsi`/`XTypes.fs`, because a root module cannot declare a type of its namespace. Modules carry no `[<CompiledName>]`. - D12 (new): the comparers that a map or a set keeps come only through one `Comparable*` struct per collection, whose members are the creation functions with the comparers applied. It replaces the `*WithComparer(s)`, `*WithKeyComparer` and `with*Comparer(s)` functions. - D13 (new): `ofArray`, `ofList` and `ofSeq` of the maps are static extension members in an `[<AutoOpen>]` `XExtensions` module, overloaded for `KeyValuePair`, reference tuples and struct tuples. `ofKeyValuePairs` and the `Tuple` creation functions go; `setItems` takes struct tuples like `addRange`. The ADR also records what the implementation found: the explicit type parameters of the alternate lookups (FS0687), the `comparison` constraint and the cached default comparer of the sorted collections, the O(n) `maxKeyValue` of `SortedMap`, and why `keys`/`values` return different types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…FSharp.Core `Map` module Comments only; the code without them is the same. The references to the ADRs leave the comments, because the documentation of the internal modules is in the XML of the package too. The cases of the option types are `<see cref>`, not `<c>`. `<summary>` and `<remarks>` take one line each when their own text has up to 60 characters, whatever the length of the other one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd `IMap` The references to the ADRs leave the comments of the tests. No code changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…FSharp.Core `Map` module
`yield!` and `for` of `hashMap { }` take `Span`, `ReadOnlySpan`, `Memory` and `ReadOnlyMemory`. A function cannot keep a
span, so a span is copied at once; a memory is read in place. The documentation says where a span does not compile.
The buffer abbreviation stays public, because the inline members use it: an internal abbreviation breaks every other assembly
that uses the expression with FS1118. It is hidden from completion and warned about, as FSharp.Core does for `TaskCode`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd `IMap`
Tests of `hashMap { }`: `yield!` and `for` over spans and memories, and `yield!` of the body of another expression, which
adds to what the expression has.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ble and the tutorial The expression takes spans and memories. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…FSharp.Core `Map` module Comments only: the overloads of `yield!` for spans and memories have the remarks of the other overloads, a `<c>` element stays on one line, and the remarks of `Raise.keyNotFound` say which message it does not have. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd `IMap` The test of `yield!` compares the instances that the parts of the expression get: it fails when a part gets another collector than the part before it, which the counts alone do not show. A blank line separates two static members. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd `IMap`
The resource of `use` and the compensation of `try finally` in `hashMap { }` have to wait for the end of the body: the tests passed
also for an expression that disposes the resource first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Proposed Changes
Rewrites
HashMap(ImmutableDictionary<'Key, 'Value>) and adds the interface moduleIMap(IImmutableDictionary<'Key, 'Value>) after ADR 0001 (#23). It builds on #26 (FlatList), which is merged intomain.The branch follows the reworked ADR, and the three points of the review are done: the modules are root modules, a comparer struct creates hash maps with comparers, and extension overloads take the bindings in every shape.
HashMap/HashMapTypes.fs: the abbreviationsHashMap<'Key, 'Value>andIMap<'Key, 'Value>.HashMap,IMapand theirOptionandTuplemodules are the root modules of their files (D2), and a root module cannot declare a type of its namespace.HashMap/HashMap.fsiandHashMap.fs: 48 functions, in the canonical category order, and the nested modulesTupleandValueTuple. They are theHashMapcolumn of ADR Appendix B, with the parameter names of the FSharp.CoreMapmodule (key,value,table,elements,fand so on) andspanfor a span, as inFlatList.partition,toArray,toListandtoSeqreturn struct tuples (D3).build,builder,ofBuilder,toBuilderandupdate,add,addRange,containsBinding,containsValue,ofReadOnlySpan,ofSeqBy,removeRange,setItem,setItemsandtryGetKey.addis the BCLAdd, as the 1.0.0 function was (the maintainer's decision): a key that is bound to a value that the value comparer finds different throwsArgumentException, an equal binding returns the input itself, and a new key is added.Map.addreplaces the value, andsetItemis the function that does;changeadds a binding only when the key has none. There is noaddNew.containsBinding key value tablewrapsContainsof aKeyValuePair, so the value comparer of the map decides whether the values are equal;tryFindfollowed by=compares with F# equality instead.IMaphas it too, where the comparers are out of reach.ofReadOnlySpan spanandofSpan spancreate a map from aReadOnlySpanor aSpanofKeyValuePair<_, _>(CreateRangeWithOverwrite, which takes a read-only span only); a repeated key never throws. The pair exists because F# converts aSpanto the parameter ofofReadOnlySpanonly when it has inferred the types of the call (otherwise FS0001), asFlatListhasofReadOnlySpanandofSpan. An array converts to either parameter under the same condition.build actionandupdate action tablefill or change a builder with an action, asFlatList.buildandupdatedo.updatereturns the input itself when the action changes nothing.addRangeandsetItemstakeKeyValuePairs. The nested modules hold them for reference and struct tuples (D13):HashMap.Tuple.addRange pairs table,HashMap.ValueTuple.setItems pairs table.forComparersandforKeyComparercreate the comparer struct.chooseis an extra.HashMap/HashMap.CustomComparers.fsiand.fs(D12): the structCustomComparersHashMap<'Key, 'Value>holds the key comparer and the value comparer,(keyComparer, valueComparer), or the key comparer andEqualityComparer<'Value>.Default,(keyComparer).KeyComparerandValueComparer. Its members have the names of the creation functions and PascalCase compiled names:empty,singleton,ofArray,ofListandofSeqin the three shapes,ofReadOnlySpan,ofSpan,ofSeqBy,buildandbuilder.HashMap.forComparers keyComparer valueComparerandHashMap.forKeyComparer keyComparercreate it:(HashMap.forKeyComparer StringComparer.OrdinalIgnoreCase).ofSeq pairs.nullcomparer throwsArgumentNullExceptionwith the name of its parameter, in the constructors and in thefor*functions. The default value of the struct stands for the default comparers.ofReadOnlySpanwrapsCreateRangeWithOverwritefor the default value comparer. The BCL overload with a key comparer has no value comparer, so another one sets the bindings in a builder with the comparers, which gives the same result; a test runs both paths on the same bindings.ofSpanpasses its span toofReadOnlySpan.ofSeqgives an existing map the comparers of the struct, which is how to change the comparers of a map. It differs fromWithComparersin three ways that the remarks and an example now state: it takes O(1) only when the key comparer of the map is the instance of the struct, keys that become equal merge whereWithComparersthrows, andforKeyComparerresets the value comparer.HashMap/HashMap.Extensions.fsiand.fs(D13): the auto-opened moduleHashMapExtensionsextendsImmutableDictionary<'Key, 'Value>with staticofArray,ofListandofSeq, each overloaded forKeyValuePairs, reference tuples and struct tuples.HashMapmodule has no function with their names, soHashMap.ofSeq pairsreaches the overloads, also aspairs |> HashMap.ofSeq. Lists, arrays,dict, an F#Mapand an existing hash map resolve.ImmutableDictionary. It calls the public static methodsHashMapExtensions.OfArray,OfListandOfSeq(checked by reflection) or uses the struct. A reflection over theHashMapmodule does not list them.CreateRangerejects another value of it. The rejecting form isHashMap.empty |> HashMap.addRange pairs.DependentUponin the project file, the.fsionHashMap.fsiand the.fsonHashMap.fs, so that Visual Studio shows them under the module. Their names start with the name of the module; the compile order and the names of the struct and the module stay.HashMap/IMap.fsiandIMap.fs: 33 functions overIImmutableDictionary, and the nested modulesTupleandValueTuplewithaddRangeandsetItems.addis theAddof the interface andcontainsBindingitsContainsof aKeyValuePair; the latter is the one member of the interface that no other function reaches. The interface declares no creation, builder, comparer orcontainsValuemembers, so the module has no such functions.filterandpartitionkeep the implementation of the map (Clear ()plusAddRange). When every binding stays, they return the input itself.mapandchoosereturn aHashMapwith the default comparers.ImmutableDictionary.SetItem,Add,AddRange,ToImmutableDictionaryand the indexer of the builder do. This holds foradd,change,setItem,setItems,addRange, theirTuple,ValueTupleandOptionvariants,IMap, the creation functions and members,ofReadOnlySpan,ofSpan,buildandhashMap { }. The functions that set one binding then return the input itself;addthrows for another value. The remarks of every affected function and member say so,IMap.mapandIMap.chooseincluded, where keys that only the default comparer finds equal keep the first of equal results.ofArray,ofList,ofSeq,ofReadOnlySpanandofSpankeep the last binding of a key in every shape, asMap.ofSeqdoes, both as extension members and as members of the struct, unless the value comparer finds the two values equal: then the earlier binding stays (D14).add,ofSeqByandaddRangekeep the behavior ofImmutableDictionary. A repeated key with an equal value is accepted and keeps the first binding; a repeated key with another value throwsArgumentException.setItemandsetItemsreplace the value.findandpickthrowKeyNotFoundExceptionasMapdoes.findKeythrows the message thatMap.findKeygets fromSeq.pick.seqargument throwsArgumentNullExceptionthat names the parameter fornulland for a default flat list given as a sequence, which would otherwise fail withInvalidOperationExceptioninside the BCL call. One call ofcheckNotNullOrDefaultSeqguards each of these before anything else:ofSeqBy,addRange,removeRangeandsetItemsofHashMapand ofIMap, theTupleandValueTuplemodules of both, theofSeqandofSeqBymembers of the struct (the extension overloads call them), andyield!andforofhashMap { }, which check when the member runs and not when the buffer does;yield!of an array and of a hash map checks fornullthe same way, withArgumentNullExceptionthat namespairsortable. Arrays keep their null check.foldBack:foldBackvisits the bindings in the reverse order of their enumeration. Its remarks say so.HashMapOptionandIMapOptioncontainchange,choose,pick,tryFind,tryFindKey,tryGetKeyandtryPickwith options.HashMapTupleandIMapTuplecontainpartition,toArray,toListandtoSeqwith reference tuples. The functions that take bindings need no counterpart there, and the nested modulesTupleandValueTupleresolve afteropen FSharp.Collections.Immutable.Tupletoo.hashMap { }yieldsstruct (key, value)orKeyValuePair, and a later binding of a key wins unless its value is equal (D14).HashMapCE keyComparer { }takes a key comparer, and anullone throwsArgumentNullException.HashMapCE<'Key>is generic in the key type, because its comparer has that type, sohashMapis a type function:[<GeneralizableValue>] let hashMap<'Key when 'Key : not null> = HashMapCE<'Key> ().HashMap/HashMapCE.fsi, compiled right beforeHashMapCE.fs, carries the documentation of the builder;Usingtakes'Resource :> IDisposable | null.ComputationExpressions.fsideclareshashMapafterflatList, under theCreationbanner.mainthat the struct replaces:emptyWithComparers,emptyWithKeyComparer,ofKeyValuePairs,ofKeyValuePairsWithKeyComparer,ofSeqWithKeyComparer,builderWithComparers,builderWithKeyComparer,withComparersandwithKeyComparer. The published 1.0.0 did not have them, so the changelog does not list them as removed. The struct replaces them, andofKeyValuePairsis theKeyValuePairoverload ofofSeq.addRangeandsetItemstake the same shape,KeyValuePairs, and the nested modulesTupleandValueTupletake the tuples.ofSeqBykeeps the behavior of the BCL.HashMap.keysandvaluesreturnICollection<_>, asMap.keysandMap.valuesdo.IMap.keysandvaluesreturnseq<_>, because the interface only exposesIReadOnlyDictionary.Keys(ADR Appendix B).addworks as in the BCL, as it did in 1.0.0: it throws for a key bound to another value, andsetItemreplaces. The first version of this rewrite madeaddreplace, which was a mistake; the changelog no longer says thataddchanged.Helper/:Raise.keyNotFoundis new (Helper/Raise.fs).Dictionaries, inHelper/Dictionaries.fs, holds the algorithms overseq<KeyValuePair>andIDictionaryand the deconstructors of the binding shapes,splitKeyValuePairandsplitTuple, so thatSortedMap,FrozenMapand the interface modules can reuse them.Maps.fs: only the legacySortedMapremains. The legacyHashMapmodule and theHashMap,HashMapBuilderandIMapabbreviations are removed.docsSrc/Tutorials/Getting_Started.mdcreates its hash map from reference tuples and showsHashMap.forKeyComparer. The changelog lists the struct, the overloads, the nested modules, the new functions and the values that the value comparer finds equal. It also says what the API gap analysis found undocumented, and the remarks of the functions repeat it where users look:ofSeqof the struct andWithComparers, with an example, and a pointer fromforComparersandforKeyComparer;HashMap.empty |> HashMap.addRange pairs, and the recipe forToImmutableDictionarywith an element selector;TryGetValue(tryFind),GetValueOrDefault(tryFindfollowed byValueOption.defaultValue) andTryAdd(change);IMaphas only what the interface declares;length,append,except,checkandHashMapBuilder), each with its replacement, and the three functions whose behavior differs from 1.0.0 (tryFind,ofSeqandfilter); both lists were checked against the published 1.0.0 package.Tests: 4057 per target framework, 1297 of them for
HashMap(805) andIMap(492).DataRowandDynamicDatarows, so every case runs and reports as a test of its own. The 1045 cases of the former 347 tests became 1044 rows: the test that the order of enumeration is the order of the key/value pairs merged into the rows oftoArray, and the comparers ofmapandchooseare a row each.Contracts/(MapOps.fs,MapInputs.fs,MapContract,MapTransformContract,MapMutationContractandMapCreationContract) compare every function with FSharp.CoreMap.MapInputsis a static class whose properties build new arrays on each read.findKey,tryFindKey,pick,tryPick,fold,foldBack,iter,toArray,toSeq,keysandvalues;toArrayis compared with the map's own enumeration of key/value pairs, because a hash map does not keep the order of its input.Map, except that ofadd, which is compared with the BCL member that it wraps.change, binding shapes and the implementations behindIMapare union cases, and the tables of functions are F# maps whose keys are the rows.ofArray,ofListandofSeqin the three shapes on every input, the bindings that repeat a key included. It takesdict, an F#Mapand an existing map as sources ofKeyValuePairs, and checks that every created map finds its keys with its key comparer.addRangeandsetItemsin the three shapes: the module forKeyValuePairs, the nested modules for tuples. It comparesaddwithMap.addonly for keys without a binding; for the keys of the input it checks the BCL result, the input itself for an equal binding andArgumentExceptionfor another value.containsBindingon every binding, every key with another value and every absent key. The tests of the modules check it with a value comparer that ignores the case, wheretryFindand=disagree with the BCL, on both implementations ofIMap, and check that a null key is left to the key comparer.HashMapderives all four facets, and the creation facet a second time forCustomComparersHashMapwith a key comparer.IMapderives all of them except creation.IMap, every member of the struct, every shape of the extension members and every member ofhashMap { }that sets a binding, with a value comparer that finds distinct values equal or with copies of strings that the default comparer finds equal.addhas a row for the equal value (the input itself) and for another value (it throws).ofReadOnlySpanandofSpanare tested once per function, as the cases of a union that builds the span of an array inside its own members: for the module and for both paths of the struct (the default value comparer and another one), on bindings whose keys differ in their case, against the rule of D14 and against each other; they copy the span, and take an array when the types of the call are known.buildandupdateare tested for the bindings, the comparers, the input that stays unchanged and the null table.nulland for a default flat list, for the module,IMap, the members of the struct andhashMap { }; the extension overloads run through the module and the struct.yield!of a null array and of a null hash map has a row too. A default flat list of strings given asseq<obj>has a row per module (FlatListOracles.defaultStringsAsObjects), and a flat list that is not default is checked to pass.forKeyComparer StringComparer.OrdinalIgnoreCase, the last binding in every shape, pipelines and the nested modules afteropen FSharp.Collections.Immutable.Tuple.Types of changes
What types of changes does your code introduce to FSharp.Collections.Immutable?
Put an
xin the boxes that applyThese changes break existing code; the list compares with the published 1.0.0, as the changelog does:
tryFindreturns avoption, where it returned anoption.ofSeqkeeps the last binding of a repeated key instead of throwing.filterreturns the bindings that satisfy the predicate, where it returned all the bindings.length,append,except,checkand theHashMapBuilderabbreviation are gone; the Removed section of the changelog names their replacements.HashMapExtensionsor through the struct.Checklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
ADR 0001, D14 says that a sorted map also keeps the stored key for an equal value. A hash map keeps it too:
ImmutableDictionary.SetItemand the indexer of its builder leave the whole binding as it is, so the documentation ofHashMapsays "its key included" as well.🤖 Generated with Claude Code
Summary by CodeRabbit
HashMapandIMapAPIs for creating, searching, transforming, and converting maps, with custom comparers, builders, tuple inputs, and option-based operations.hashMap { }computation expression for building maps.HashMap.tryFindnow returns a value option.