ExtCore icon indicating copy to clipboard operation
ExtCore copied to clipboard

Thread safe Dict doesnt return dict

Open CumpsD opened this issue 11 years ago • 2 comments

Any reason these operations dont return dict, while the non-Safe do?

https://github.com/jack-pappas/ExtCore/blob/master/ExtCore/Collections.Dict.fs#L331-L337

Why not:

let updateOrAdd key value (dict : dict<'Key, 'T>) =
    // Preconditions
    checkNonNull "dict" dict

    if dict.IsReadOnly then
        invalidOp "Cannot update or add an entry to a read-only dictionary."
    lock dict <| fun () ->
        dict.[key] <- value

    dict

CumpsD avatar Mar 29 '15 16:03 CumpsD

Hmm. There might have been a good reason for it at one point, but I don't remember now.

If I had to guess, it may be because returning the dictionary instance makes the function signatures more like those in the Map module.

Whatever the reason was before, the inconsistency seems like a code smell now so I'll keep this open as a work item for the first major ExtCore release (v1.0). There's no ETA for that release but I do have a few other small, breaking changes to make to other parts of the library at some point so it'd be best to group them all together.

jack-pappas avatar Apr 18 '15 19:04 jack-pappas

Thanks :) I've temporarily included a modified version in my project ;)

CumpsD avatar Apr 18 '15 19:04 CumpsD