ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: shyouhei@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:100271] [Ruby master Feature#17208] Add `Set#compact` and `Set#compact!` methods
Date: Fri, 02 Oct 2020 00:47:38 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-87858.20201002004738.9869@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17208.20201001193201.9869@ruby-lang.org

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/

  parent reply	other threads:[~2020-10-02  0:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-87858.20201002004738.9869@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).