Stream: general

Topic: HashMap::insert vs HashSet::insert

Jake Goulding (Jun 12 2019 at 15:38, on Zulip):

I am reminded of this annoying footgun:

If the map did not have this key present, None is returned.

If the set did not have this value present, true is returned.

oli (Jun 12 2019 at 15:39, on Zulip):

that one has bitten me so many times

simulacrum (Jun 12 2019 at 16:00, on Zulip):

fwiw I personally consider the bool return type on HashSet::insert to be a mistake, we should've made it an enum (with methods to check for each variant, perhaps)

simulacrum (Jun 12 2019 at 16:00, on Zulip):

I don't think I've ever gotten the true/false to match with what I actually wanted in code

Last update: Jun 04 2020 at 18:40UTC