[#86787] [Ruby trunk Feature#14723] [WIP] sleepy GC — ko1@...

Issue #14723 has been updated by ko1 (Koichi Sasada).

13 messages 2018/05/01
[#86790] Re: [Ruby trunk Feature#14723] [WIP] sleepy GC — Eric Wong <normalperson@...> 2018/05/01

ko1@atdot.net wrote:

[#87095] [Ruby trunk Feature#14767] [PATCH] gc.c: use monotonic counters for objspace_malloc_increase — ko1@...

Issue #14767 has been updated by ko1 (Koichi Sasada).

9 messages 2018/05/17

[ruby-core:87271] [Ruby trunk Feature#14788] `Hash#keys` Could Accept a Block

From: hanmac@...
Date: 2018-05-28 06:19:45 UTC
List: ruby-core #87271
Issue #14788 has been updated by Hanmac (Hans Mackowiak).


I don't like it.

From `keys {|k| k.something }` I wouldn't know what it does with the keys, if they would select or map the keys or both.

Is probably against that "least surprise" thing

----------------------------------------
Feature #14788: `Hash#keys` Could Accept a Block
https://bugs.ruby-lang.org/issues/14788#change-72261

* Author: rringler (Ryan Ringler)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Sometimes I only need to fetch *some* of the keys from a Hash. With the current `Hash#keys` implementation, this requires fetching all the keys and then selecting the ones I'm interested in. It would be nice if `Has#keys` accepted a block, and only returned the keys for which the block evaluated to true.

**Currently:**
~~~ruby
{ 1 => '1', 2 => '2', 3 => '3', 4 => '4' }.keys.select { |key| key.odd? } # => [1, 3]
~~~

**Proposed:**
~~~ruby
{ 1 => '1', 2 => '2', 3 => '3', 4 => '4' }.keys { |key| key.odd? } # => [1, 3]
~~~

The attached patch shows how `rb_hash_keys` might be modified to check for a passed block.

---Files--------------------------------
hash_keys_block.patch (2.27 KB)


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

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next