I'm migrating my F# code from dotnet3.1 to 5 and struggling with following code:
let tryRemove key (dict: Concurrent.ConcurrentDictionary<'a, 'b>) =
match dict.TryRemove(key) with
| (true, v) -> Some v
| (false, _) -> None
In 3.1 TryRemove returned tuple, in version 5 it returnes only boolean value. To get value from dictionary I need to pass reference as second parameter of TryRemove.
What is the correct way to do it and avoid returning null v?
I have tried following code:
let tryRemove key (dict: Concurrent.ConcurrentDictionary<'a, 'b>): 'b option =
let mutable v: 'b = null
match dict.TryRemove(key, &v) with
| true -> Some v
| _ -> None
But now function that uses it thinks that it is possible to have null inside that Option from tryRemove
error FS0001: The type '(Body -> unit)' does not have 'null' as a proper value
where b' is (Body -> unit)