Skip to content

Commit 1889450

Browse files
xperiandriclaude
andcommitted
docs: FrozenSet in the changelog and the collection table
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5c4de4c commit 1889450

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,52 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8484
`tryGetValue` with options, and `partition` and `partitionWith` with reference tuples.
8585
* `hashSet { }` builds a hash set, and `HashSetCE` created with an equality comparer builds hash sets that compare with it;
8686
a `null` comparer throws `ArgumentNullException`.
87+
* `FrozenSet` works on `System.Collections.Frozen.FrozenSet<'T>` with the functions of the FSharp.Core `Set` module that
88+
read a set or transform a whole set, with their semantics, argument order and exceptions, plus `choose`, `comparer`,
89+
`forComparer`, `ofReadOnlySpan`, `ofSpan`, `overlaps`, `setEquals`, `symmetricDifference`, `toFlatList`, which returns
90+
the elements without a copy, and `tryGetValue`. A frozen set is built once: the module has no function that adds or
91+
removes an element, and every transformation builds a new frozen set. `FrozenSet.union set (FrozenSet.singleton value)`
92+
and `FrozenSet.difference set (FrozenSet.singleton value)` do what `Set.add` and `Set.remove` do, each as an O(n)
93+
rebuild that compares in the comparer of `set`. Every function throws `ArgumentNullException` for a `null` frozen set,
94+
sequence, list or array, and for a default flat list that is given as a sequence; `yield!` and `for` of
95+
`frozenSet { }` do the same.
96+
* `FrozenSet.ofReadOnlySpan` and `ofSpan` create a frozen set from a span. They wrap `FrozenSet.Create`, and of the
97+
elements that the comparer finds equal the first stays.
98+
* `FrozenSet.forComparer comparer` creates the `CustomComparerFrozenSet` struct, whose members `empty`, `ofArray`,
99+
`ofList`, `ofReadOnlySpan`, `ofSeq`, `ofSpan` and `singleton` create frozen sets that compare with the comparer, as in
100+
`(FrozenSet.forComparer StringComparer.OrdinalIgnoreCase).ofSeq names`. They replace the BCL methods
101+
`FrozenSet.Create(comparer, ...)` and `ToFrozenSet(source, comparer)`; `ToFrozenSet` has no `optimizeForReading`
102+
parameter in the package that the library references, so nothing is lost. `ofSeq` also gives an existing frozen set the
103+
comparer, as `ToFrozenSet` does: the frozen set itself comes back when its comparer equals the comparer of the struct.
104+
A `null` comparer throws `ArgumentNullException`, where the BCL methods take it as the default comparer:
105+
`FrozenSet.ofSeq set` gives a frozen set the default comparer, and the default value of the struct has the BCL meaning.
106+
* The members of `FrozenSet<'T>` map to the module as follows. `TryGetValue(x, out v)` is `tryGetValue x set`, which
107+
returns a `voption` (`Option.FrozenSet.tryGetValue` returns an `option`). `Items` is `toFlatList`, and `CopyTo` is
108+
`toFlatList` followed by `FlatList.blit` or `FlatList.asSpan`. `IsSubsetOf`, `IsProperSubsetOf`, `IsSupersetOf`,
109+
`IsProperSupersetOf`, `Overlaps` and `SetEquals` take frozen sets in the module, as the `Set` functions do. To pass a
110+
sequence, convert it with `(FrozenSet.forComparer (FrozenSet.comparer set)).ofSeq elements`: the elements get the
111+
comparer of the first frozen set, as they do in the members. `FrozenSet.ofSeq elements` converts them with the default
112+
comparer instead, which merges the elements that it finds equal before the relation sees them. The answer is that of
113+
the member when the comparer of `set` finds equal every pair of elements that the default comparer finds equal, as the
114+
default comparer and `StringComparer.OrdinalIgnoreCase` do. It can differ when the comparer of `set` tells such
115+
elements apart, as `HashIdentity.Reference` does for two strings with the same text. `Overlaps` and `IsSupersetOf`
116+
with a sequence are `Seq.exists` and `Seq.forall` with `FrozenSet.contains`, for every comparer. The mutating members
117+
of the interfaces, such as `ISet<T>.UnionWith` and `ICollection<T>.Add`, throw `NotSupportedException` on the BCL type
118+
and have no function.
119+
* `FrozenSet`: the element that stays when the comparer finds two elements equal follows the BCL. `union` keeps the
120+
element of the first frozen set, `intersect` keeps the elements of the second one, as `ImmutableHashSet.Intersect` and
121+
`ImmutableSortedSet.Intersect` do, because `FrozenSet<'T>` has no such member, and the creation functions keep the
122+
first element of their input. `isProperSuperset` counts the elements of the second frozen set that the comparer of the
123+
first one finds equal once, as `FrozenSet<'T>.IsProperSupersetOf` does.
124+
* On `net10.0`, `FrozenSet.alternateLookup` and `FrozenSet.tryAlternateLookup` return the alternate lookup of a frozen set
125+
whose comparer compares the elements with values of another type. They are `GetAlternateLookup` and
126+
`TryGetAlternateLookup`. The alternate type comes first, as in `FrozenSet.alternateLookup<int, _> set`, and a lookup by a
127+
`ReadOnlySpan<char>` calls the BCL method directly, because an F# generic function cannot be instantiated with a
128+
byref-like type.
129+
* The `FSharp.Collections.Immutable.Option.FrozenSet` and `FSharp.Collections.Immutable.Tuple.FrozenSet` modules repeat
130+
`choose`, `tryGetValue` and `tryAlternateLookup` with options, and `partition` and `partitionWith` with reference tuples.
131+
* `frozenSet { }` builds a frozen set, and `FrozenSetCE` created with an equality comparer builds frozen sets that compare
132+
with it; a `null` comparer throws `ArgumentNullException`.
87133

88134
### Changed
89135

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Please also join the [F# Open Source Group](http://fsharp.github.com)
2121
| `HashSet` | `ImmutableHashSet<'T>` | `hashSet { }` |
2222
| `SortedSet` | `ImmutableSortedSet<'T>` | – |
2323
| `ISet` | `IImmutableSet<'T>` | – |
24+
| `FrozenSet` | `FrozenSet<'T>` | `frozenSet { }` |
2425
| `IIndexedSeq` | `IReadOnlyList<'T>` | – |
2526

2627
[Documentation](https://fsprojects.github.io/FSharp.Collections.Immutable/)

‎docsSrc/Explanations/Background.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ While F# has its own built-in immutable collections, System.Collections.Immutabl
3535
| `HashSet` | `ImmutableHashSet<'T>` | `hashSet { }` |
3636
| `SortedSet` | `ImmutableSortedSet<'T>` | – |
3737
| `ISet` | `IImmutableSet<'T>` | – |
38+
| `FrozenSet` | `FrozenSet<'T>` | `frozenSet { }` |
3839
| `IIndexedSeq` | `IReadOnlyList<'T>` | – |
3940

4041
---

‎docsSrc/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ F# bindings for [System.Collections.Immutable](https://learn.microsoft.com/en-us
1717
| `HashSet` | `ImmutableHashSet<'T>` | `hashSet { }` |
1818
| `SortedSet` | `ImmutableSortedSet<'T>` | – |
1919
| `ISet` | `IImmutableSet<'T>` | – |
20+
| `FrozenSet` | `FrozenSet<'T>` | `frozenSet { }` |
2021
| `IIndexedSeq` | `IReadOnlyList<'T>` | – |
2122

2223
---

0 commit comments

Comments
 (0)