* [ruby-core:100259] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods
@ 2020-10-01 19:32 koic.ito
2020-10-01 22:24 ` [ruby-core:100267] " marcandre-ruby-core
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: koic.ito @ 2020-10-01 19:32 UTC (permalink / raw)
To: ruby-core
Issue #17208 has been reported by koic (Koichi ITO).
----------------------------------------
Feature #17208: Add `Set#compact` and `Set#compact!` methods
https://bugs.ruby-lang.org/issues/17208
* Author: koic (Koichi ITO)
* Status: Open
* Priority: Normal
----------------------------------------
This is a proposal to add `compact` and `compact!` methods already owned by `Array` and `Hash` to `Set`.
- `Array#compact` and `Array#compact!` has been around for a long time.
- `Hash#compact` has `Hash#compact!` been added since Ruby 2.4 ... https://bugs.ruby-lang.org/issues/11818
- There is `Set` in collection libraries other than `Array` and `Hash`. But `Set` doesn't have `compact` and `compact!` methods.
It behaves the same as `compact` and `compact!` methods of `Array` and `Hash` as follows.
`Set#compact!`:
```ruby
# Removes all nil elements from self. Returns self if any elements removed, otherwise nil.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact! #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact! #=> nil
set #=> #<Set: {1, "c"}>
```
`Set#compact`:
```ruby
# Returns a new Set containing all non-nil elements from self.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c", nil}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
```
Pull Request ... https://github.com/ruby/ruby/pull/3617
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:100267] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods
2020-10-01 19:32 [ruby-core:100259] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods koic.ito
@ 2020-10-01 22:24 ` marcandre-ruby-core
2020-10-02 0:47 ` [ruby-core:100271] " shyouhei
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: marcandre-ruby-core @ 2020-10-01 22:24 UTC (permalink / raw)
To: ruby-core
Issue #17208 has been updated by marcandre (Marc-Andre Lafortune).
I second
----------------------------------------
Feature #17208: Add `Set#compact` and `Set#compact!` methods
https://bugs.ruby-lang.org/issues/17208#change-87854
* Author: koic (Koichi ITO)
* Status: Open
* Priority: Normal
----------------------------------------
This is a proposal to add `compact` and `compact!` methods already owned by `Array` and `Hash` to `Set`.
- `Array#compact` and `Array#compact!` has been around for a long time.
- `Hash#compact` has `Hash#compact!` been added since Ruby 2.4 ... https://bugs.ruby-lang.org/issues/11818
- There is `Set` in collection libraries other than `Array` and `Hash`. But `Set` doesn't have `compact` and `compact!` methods.
It behaves the same as `compact` and `compact!` methods of `Array` and `Hash` as follows.
`Set#compact!`:
```ruby
# Removes all nil elements from self. Returns self if any elements removed, otherwise nil.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact! #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact! #=> nil
set #=> #<Set: {1, "c"}>
```
`Set#compact`:
```ruby
# Returns a new Set containing all non-nil elements from self.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c", nil}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
```
Pull Request ... https://github.com/ruby/ruby/pull/3617
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:100271] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods
2020-10-01 19:32 [ruby-core:100259] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods koic.ito
2020-10-01 22:24 ` [ruby-core:100267] " marcandre-ruby-core
@ 2020-10-02 0:47 ` shyouhei
2020-10-02 3:02 ` [ruby-core:100275] " marcandre-ruby-core
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: shyouhei @ 2020-10-02 0:47 UTC (permalink / raw)
To: ruby-core
Issue #17208 has been updated by shyouhei (Shyouhei Urabe).
I like the feature, but isn't "Compact Set" a mathematical concept that refers to something different?
----------------------------------------
Feature #17208: Add `Set#compact` and `Set#compact!` methods
https://bugs.ruby-lang.org/issues/17208#change-87858
* Author: koic (Koichi ITO)
* Status: Open
* Priority: Normal
----------------------------------------
This is a proposal to add `compact` and `compact!` methods already owned by `Array` and `Hash` to `Set`.
- `Array#compact` and `Array#compact!` has been around for a long time.
- `Hash#compact` has `Hash#compact!` been added since Ruby 2.4 ... https://bugs.ruby-lang.org/issues/11818
- There is `Set` in collection libraries other than `Array` and `Hash`. But `Set` doesn't have `compact` and `compact!` methods.
It behaves the same as `compact` and `compact!` methods of `Array` and `Hash` as follows.
`Set#compact!`:
```ruby
# Removes all nil elements from self. Returns self if any elements removed, otherwise nil.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact! #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact! #=> nil
set #=> #<Set: {1, "c"}>
```
`Set#compact`:
```ruby
# Returns a new Set containing all non-nil elements from self.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c", nil}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
```
Pull Request ... https://github.com/ruby/ruby/pull/3617
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:100275] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods
2020-10-01 19:32 [ruby-core:100259] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods koic.ito
2020-10-01 22:24 ` [ruby-core:100267] " marcandre-ruby-core
2020-10-02 0:47 ` [ruby-core:100271] " shyouhei
@ 2020-10-02 3:02 ` marcandre-ruby-core
2020-11-05 9:41 ` [ruby-core:100717] " bozhidar
2020-11-05 10:44 ` [ruby-core:100719] " eregontp
4 siblings, 0 replies; 6+ messages in thread
From: marcandre-ruby-core @ 2020-10-02 3:02 UTC (permalink / raw)
To: ruby-core
Issue #17208 has been updated by marcandre (Marc-Andre Lafortune).
shyouhei (Shyouhei Urabe) wrote in #note-2:
> I like the feature, but isn't "Compact Set" a mathematical concept that refers to something different?
It can, but the idea requires infinite sets, and all elements belonging to a topological space, I doubt many people would actually be confused.
----------------------------------------
Feature #17208: Add `Set#compact` and `Set#compact!` methods
https://bugs.ruby-lang.org/issues/17208#change-87862
* Author: koic (Koichi ITO)
* Status: Open
* Priority: Normal
----------------------------------------
This is a proposal to add `compact` and `compact!` methods already owned by `Array` and `Hash` to `Set`.
- `Array#compact` and `Array#compact!` has been around for a long time.
- `Hash#compact` has `Hash#compact!` been added since Ruby 2.4 ... https://bugs.ruby-lang.org/issues/11818
- There is `Set` in collection libraries other than `Array` and `Hash`. But `Set` doesn't have `compact` and `compact!` methods.
It behaves the same as `compact` and `compact!` methods of `Array` and `Hash` as follows.
`Set#compact!`:
```ruby
# Removes all nil elements from self. Returns self if any elements removed, otherwise nil.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact! #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact! #=> nil
set #=> #<Set: {1, "c"}>
```
`Set#compact`:
```ruby
# Returns a new Set containing all non-nil elements from self.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c", nil}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
```
Pull Request ... https://github.com/ruby/ruby/pull/3617
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:100717] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods
2020-10-01 19:32 [ruby-core:100259] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods koic.ito
` (2 preceding siblings ...)
2020-10-02 3:02 ` [ruby-core:100275] " marcandre-ruby-core
@ 2020-11-05 9:41 ` bozhidar
2020-11-05 10:44 ` [ruby-core:100719] " eregontp
4 siblings, 0 replies; 6+ messages in thread
From: bozhidar @ 2020-11-05 9:41 UTC (permalink / raw)
To: ruby-core
Issue #17208 has been updated by bozhidar (Bozhidar Batsov).
I like the proposal. I also wonder if we shouldn't be able to able to reject nils at Set creation time, as nil rarely makes sense as a set value.
----------------------------------------
Feature #17208: Add `Set#compact` and `Set#compact!` methods
https://bugs.ruby-lang.org/issues/17208#change-88361
* Author: koic (Koichi ITO)
* Status: Open
* Priority: Normal
----------------------------------------
This is a proposal to add `compact` and `compact!` methods already owned by `Array` and `Hash` to `Set`.
- `Array#compact` and `Array#compact!` has been around for a long time.
- `Hash#compact` has `Hash#compact!` been added since Ruby 2.4 ... https://bugs.ruby-lang.org/issues/11818
- There is `Set` in collection libraries other than `Array` and `Hash`. But `Set` doesn't have `compact` and `compact!` methods.
It behaves the same as `compact` and `compact!` methods of `Array` and `Hash` as follows.
`Set#compact!`:
```ruby
# Removes all nil elements from self. Returns self if any elements removed, otherwise nil.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact! #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact! #=> nil
set #=> #<Set: {1, "c"}>
```
`Set#compact`:
```ruby
# Returns a new Set containing all non-nil elements from self.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c", nil}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
```
Pull Request ... https://github.com/ruby/ruby/pull/3617
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:100719] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods
2020-10-01 19:32 [ruby-core:100259] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods koic.ito
` (3 preceding siblings ...)
2020-11-05 9:41 ` [ruby-core:100717] " bozhidar
@ 2020-11-05 10:44 ` eregontp
4 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2020-11-05 10:44 UTC (permalink / raw)
To: ruby-core
Issue #17208 has been updated by Eregon (Benoit Daloze).
bozhidar (Bozhidar Batsov) wrote in #note-4:
> I like the proposal. I also wonder if we shouldn't be able to able to reject nils at Set creation time, as nil rarely makes sense as a set value.
With some option then?
I believe generic collections should accept any element, no special handling of nil or any other object.
(there might be additional requirements like #hash/#eql?, but any object can implement them)
----------------------------------------
Feature #17208: Add `Set#compact` and `Set#compact!` methods
https://bugs.ruby-lang.org/issues/17208#change-88363
* Author: koic (Koichi ITO)
* Status: Open
* Priority: Normal
----------------------------------------
This is a proposal to add `compact` and `compact!` methods already owned by `Array` and `Hash` to `Set`.
- `Array#compact` and `Array#compact!` has been around for a long time.
- `Hash#compact` has `Hash#compact!` been added since Ruby 2.4 ... https://bugs.ruby-lang.org/issues/11818
- There is `Set` in collection libraries other than `Array` and `Hash`. But `Set` doesn't have `compact` and `compact!` methods.
It behaves the same as `compact` and `compact!` methods of `Array` and `Hash` as follows.
`Set#compact!`:
```ruby
# Removes all nil elements from self. Returns self if any elements removed, otherwise nil.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact! #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact! #=> nil
set #=> #<Set: {1, "c"}>
```
`Set#compact`:
```ruby
# Returns a new Set containing all non-nil elements from self.
set = Set[1, 'c', nil] #=> #<Set: {1, "c", nil}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c", nil}>
set = Set[1, 'c'] #=> #<Set: {1, "c"}>
set.compact #=> #<Set: {1, "c"}>
set #=> #<Set: {1, "c"}>
```
Pull Request ... https://github.com/ruby/ruby/pull/3617
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-11-05 10:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-01 19:32 [ruby-core:100259] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods koic.ito
2020-10-01 22:24 ` [ruby-core:100267] " marcandre-ruby-core
2020-10-02 0:47 ` [ruby-core:100271] " shyouhei
2020-10-02 3:02 ` [ruby-core:100275] " marcandre-ruby-core
2020-11-05 9:41 ` [ruby-core:100717] " bozhidar
2020-11-05 10:44 ` [ruby-core:100719] " eregontp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).