FSharpLint icon indicating copy to clipboard operation
FSharpLint copied to clipboard

Avoid double-lookup dictionaries: .ContainsKey key followed by indexer call .[key]

Open Thorium opened this issue 11 months ago • 0 comments

Avoid double-lookup dictionaries:

.ContainsKey key followed by .[key] should be replaced with .TryGetValue x

for example:

match xs.ContainsKey x with
| true -> ... xs.[x] ...
| false -> ///...

should be replaced with

match xs.TryGetValue x with
| true, xVal -> ... xVal ...
| false, _ -> ///...

Thorium avatar Mar 15 '24 16:03 Thorium