jack-pappas / ExtCore

An extended core library for F#.
Apache License 2.0
178 stars 32 forks source link

Thread safe Dict doesnt return dict #18

Open CumpsD opened 9 years ago

CumpsD commented 9 years ago

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
jack-pappas commented 9 years ago

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.

CumpsD commented 9 years ago

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