Implement Set#add? method#7495
Conversation
|
Why having this type of methods only for No, I don't see a real need to have it in the stdlib. It's already very easy to implement by ourself. |
asterite
left a comment
There was a problem hiding this comment.
When a value is added to a Hash you can know whether it existed or not. I think we should avoid that double check somehow (but it means adding some API to Hash)
Can you? I haven't found any way to do that...
👍 although I'm curious how to do that when the main method for insert is |
|
@j8r Because |
|
@asterite The hash lookup could be improved, but I suppose we can merge this without it (and maybe add a I'm somehow wondering about the return value |
|
Yeah, bool sounds better ai think. And I agree about delaying the optimization. |
|
@straight-shoota @asterite I've pushed a commit with proposed changes. |
73ccfc8 to
dd7b291
Compare
dd7b291 to
57acfc7
Compare
* 'master' of github.com:crystal-lang/crystal: Change the font-weight used in Playground (crystal-lang#7552) Fix formatting absolute paths (crystal-lang#7560) Refactor IO::Syscall as IO::Evented (crystal-lang#7505) YAML: fix test checking serialization of slices for libyaml 0.2.2 (crystal-lang#7555) Let Array#sort only use `<=>`, and let `<=>` return `nil` for partial comparability (crystal-lang#6611) Update `to_s` and `inspect` to have similar signatures accross the stdlib (crystal-lang#7528) Fix restriction of valid type vs free vars (crystal-lang#7536) Rewrite macro spec without executing a shell command (crystal-lang#6962) Suggest `next` when trying to break from captured block (crystal-lang#7406) Fix GenericClassType vs GenericClassInstanceType restrictions (crystal-lang#7537) Add human readable formatting for numbers (crystal-lang#6314) Add command and args to execvp error message (crystal-lang#7511) Implement Set#add? method (crystal-lang#7495)
Same as
Set#add?from Ruby's stdlib.chickendan mentioned on a Gitter chat about a need for such API to easily (in one go) distinguish whether upserted value was set before.