ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:94354] [Ruby master Feature#16104] Introduce merge_if and merge_if!
       [not found] <redmine.issue-16104.20190814180717@ruby-lang.org>
@ 2019-08-14 18:07 ` akashsjhs
  2019-08-14 18:09 ` [ruby-core:94355] " akashsjhs
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: akashsjhs @ 2019-08-14 18:07 UTC (permalink / raw)
  To: ruby-core

Issue #16104 has been reported by akash (Akash Gupta).

----------------------------------------
Feature #16104: Introduce merge_if and merge_if!
https://bugs.ruby-lang.org/issues/16104

* Author: akash (Akash Gupta)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The method `merge_if` / `merge_if` will merge the passed hash in parameter only if the block evaluates to true, otherwise not. Similar to `count` method with a block.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:94355] [Ruby master Feature#16104] Introduce merge_if and merge_if!
       [not found] <redmine.issue-16104.20190814180717@ruby-lang.org>
  2019-08-14 18:07 ` [ruby-core:94354] [Ruby master Feature#16104] Introduce merge_if and merge_if! akashsjhs
@ 2019-08-14 18:09 ` akashsjhs
  2019-08-14 20:51 ` [ruby-core:94357] " shevegen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: akashsjhs @ 2019-08-14 18:09 UTC (permalink / raw)
  To: ruby-core

Issue #16104 has been updated by akash (Akash Gupta).


akash (Akash Gupta) wrote:
> The method `merge_if` / `merge_if!` will merge the passed hash in parameter only if the block evaluates to true, otherwise not. Similar to `count` method with a block.



----------------------------------------
Feature #16104: Introduce merge_if and merge_if!
https://bugs.ruby-lang.org/issues/16104#change-80760

* Author: akash (Akash Gupta)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The method `merge_if` / `merge_if` will merge the passed hash in parameter only if the block evaluates to true, otherwise not. Similar to `count` method with a block.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:94357] [Ruby master Feature#16104] Introduce merge_if and merge_if!
       [not found] <redmine.issue-16104.20190814180717@ruby-lang.org>
  2019-08-14 18:07 ` [ruby-core:94354] [Ruby master Feature#16104] Introduce merge_if and merge_if! akashsjhs
  2019-08-14 18:09 ` [ruby-core:94355] " akashsjhs
@ 2019-08-14 20:51 ` shevegen
  2019-08-14 21:24 ` [ruby-core:94358] " sawadatsuyoshi
  2019-08-15  6:54 ` [ruby-core:94366] " janfri26
  4 siblings, 0 replies; 5+ messages in thread
From: shevegen @ 2019-08-14 20:51 UTC (permalink / raw)
  To: ruby-core

Issue #16104 has been updated by shevegen (Robert A. Heiler).


Hmmm. I have mixed feelings about it. I think being able to add something
into e. g. a Hash, based on a conditional inside of the method, may be useful.

We also have  at the least one example of "_if", such as for Array:

    .delete_if

Where (I think) this may be equal to Array#reject!.

There is no .delete_if! though, so perhaps this may apply to your feature
request too.

On the other hand ... visually I am not entirely sure whether this is 
quite elegant, although this is highly subjective.

Consider:

    if foobar
      barfoo.merge_if(b: 'Ball') {|k, v| v == 'Apple'}
    end unless blub

This is of course contrived, but the part I am unsure is whether we should
have more **NAME_if** methods as such. I can not say whether I am completely
against it, but I am a bit wary of such method names that include conditionals
in the name itself.

I think most ruby names tend to be one word; a few are two words.

(If anyone knows of more methods that have "_if" as part of their names, 
in core/stdlib, please feel free to add to the list - I really do not know
of more examples off the top of my head.)

PS: On a side note, I never manage to remember the difference between .merge()
.merge!() and .update() off-hand - I always try in irb first; I only know one
is an alias ... :D

----------------------------------------
Feature #16104: Introduce merge_if and merge_if!
https://bugs.ruby-lang.org/issues/16104#change-80763

* Author: akash (Akash Gupta)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The method `merge_if` / `merge_if` will merge the passed hash in parameter only if the block evaluates to true, otherwise not. Similar to `count` method with a block.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:94358] [Ruby master Feature#16104] Introduce merge_if and merge_if!
       [not found] <redmine.issue-16104.20190814180717@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-08-14 20:51 ` [ruby-core:94357] " shevegen
@ 2019-08-14 21:24 ` sawadatsuyoshi
  2019-08-15  6:54 ` [ruby-core:94366] " janfri26
  4 siblings, 0 replies; 5+ messages in thread
From: sawadatsuyoshi @ 2019-08-14 21:24 UTC (permalink / raw)
  To: ruby-core

Issue #16104 has been updated by sawa (Tsuyoshi Sawada).


Do

```ruby
a.each_with_object(b: 'Ball') {|(k, v), h| h[k] = v if v == 'Apple'}
```

or

```ruby
{b: 'Ball'}.merge(a.select{|k, v| v == 'Apple'})
```



----------------------------------------
Feature #16104: Introduce merge_if and merge_if!
https://bugs.ruby-lang.org/issues/16104#change-80765

* Author: akash (Akash Gupta)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The method `merge_if` / `merge_if` will merge the passed hash in parameter only if the block evaluates to true, otherwise not. Similar to `count` method with a block.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:94366] [Ruby master Feature#16104] Introduce merge_if and merge_if!
       [not found] <redmine.issue-16104.20190814180717@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-08-14 21:24 ` [ruby-core:94358] " sawadatsuyoshi
@ 2019-08-15  6:54 ` janfri26
  4 siblings, 0 replies; 5+ messages in thread
From: janfri26 @ 2019-08-15  6:54 UTC (permalink / raw)
  To: ruby-core

Issue #16104 has been updated by janfri (Jan Friedrich).


akash (Akash Gupta) wrote:
> The method `merge_if` / `merge_if!` will merge the passed hash in parameter only if the block evaluates to true, otherwise not. Similar to `count` method with a block.

What if the callee has more than one entry? For example

```ruby
a = {a: 'Apple', c: 'Pear'}
a.merge_if(b: 'Ball') {|k, v| v == 'Apple'}
# => ???
```

The block is called twice and evaluates one time `true` and the other `false`.

----------------------------------------
Feature #16104: Introduce merge_if and merge_if!
https://bugs.ruby-lang.org/issues/16104#change-80777

* Author: akash (Akash Gupta)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The method `merge_if` / `merge_if` will merge the passed hash in parameter only if the block evaluates to true, otherwise not. Similar to `count` method with a block.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-15  6:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16104.20190814180717@ruby-lang.org>
2019-08-14 18:07 ` [ruby-core:94354] [Ruby master Feature#16104] Introduce merge_if and merge_if! akashsjhs
2019-08-14 18:09 ` [ruby-core:94355] " akashsjhs
2019-08-14 20:51 ` [ruby-core:94357] " shevegen
2019-08-14 21:24 ` [ruby-core:94358] " sawadatsuyoshi
2019-08-15  6:54 ` [ruby-core:94366] " janfri26

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).