Hacker News new | ask | show | jobs
by IshKebab 20 days ago
If you access the bool through a long path maybe.

  foo.bar().baz[expensive()].qux.toggle();
4 comments

This gives me the same feeling as when I saw Rust's map Entry API

https://doc.rust-lang.org/std/collections/hash_map/enum.Entr...

    let mut map: HashMap<&str, u32> = HashMap::new();
    map.entry("poneyland").or_insert(3);
    assert_eq!(map["poneyland"], 3);
It's very ergonomic.
Alright, I'm convinced, that makes a lot of sense.
You can of course also do

  long_path_bool ^= true;
but that’s less obvious.
cant you just do

    foo.bar().baz[expensive()].qux ^= true;
Sure, but should you?
No probably not, but I think the problem is mainly on the left side of operator.

^= true , is a pretty tried and true pattern.

That's the main reason for me as well