ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:71327] [Ruby trunk - Feature #11653] [Open] Add to_proc on Hash
       [not found] <redmine.issue-11653.20151104025915@ruby-lang.org>
@ 2015-11-04  2:59 ` 6ftdan
  2015-11-04  5:24 ` [ruby-core:71329] [Ruby trunk - Feature #11653] " duerst
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: 6ftdan @ 2015-11-04  2:59 UTC (permalink / raw)
  To: ruby-core

Issue #11653 has been reported by Daniel P. Clark.

----------------------------------------
Feature #11653: Add to_proc on Hash
https://bugs.ruby-lang.org/issues/11653

* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Procs can be called the same way a hash is with `[]`.  But a Hash is not mappable as a Proc.

    my_hash = ->key{{
      a: 1, b: 2, c: 3, d: 4, e: 5, f: 6
    }[key]}

    my_hash[:a]
    # => 1

    [:e, :a, :b, :f, :c, :d].map(&my_hash) # hash is now mappable
    # => [5, 1, 2, 6, 3, 4]

This seems so straight forward I believe it should be part of the language itself with the .to_proc method call.



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

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

* [ruby-core:71329] [Ruby trunk - Feature #11653] Add to_proc on Hash
       [not found] <redmine.issue-11653.20151104025915@ruby-lang.org>
  2015-11-04  2:59 ` [ruby-core:71327] [Ruby trunk - Feature #11653] [Open] Add to_proc on Hash 6ftdan
@ 2015-11-04  5:24 ` duerst
  2015-11-04  6:01 ` [ruby-core:71330] " nobu
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: duerst @ 2015-11-04  5:24 UTC (permalink / raw)
  To: ruby-core

Issue #11653 has been updated by Martin Dürst.

Assignee set to Yukihiro Matsumoto

I think this is an excellent idea. I hope this can make it into Ruby 2.3.

----------------------------------------
Feature #11653: Add to_proc on Hash
https://bugs.ruby-lang.org/issues/11653#change-54703

* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Procs can be called the same way a hash is with `[]`.  But a Hash is not mappable as a Proc.

    my_hash = ->key{{
      a: 1, b: 2, c: 3, d: 4, e: 5, f: 6
    }[key]}

    my_hash[:a]
    # => 1

    [:e, :a, :b, :f, :c, :d].map(&my_hash) # hash is now mappable
    # => [5, 1, 2, 6, 3, 4]

This seems so straight forward I believe it should be part of the language itself with the .to_proc method call.



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

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

* [ruby-core:71330] [Ruby trunk - Feature #11653] Add to_proc on Hash
       [not found] <redmine.issue-11653.20151104025915@ruby-lang.org>
  2015-11-04  2:59 ` [ruby-core:71327] [Ruby trunk - Feature #11653] [Open] Add to_proc on Hash 6ftdan
  2015-11-04  5:24 ` [ruby-core:71329] [Ruby trunk - Feature #11653] " duerst
@ 2015-11-04  6:01 ` nobu
  2015-11-09  8:03 ` [ruby-core:71404] " matz
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: nobu @ 2015-11-04  6:01 UTC (permalink / raw)
  To: ruby-core

Issue #11653 has been updated by Nobuyoshi Nakada.

Description updated

You can write it as:

~~~ruby
[:e, :a, :b, :f, :c, :d].map(&my_hash.method(:[]))
~~~

----------------------------------------
Feature #11653: Add to_proc on Hash
https://bugs.ruby-lang.org/issues/11653#change-54704

* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Procs can be called the same way a hash is with `[]`.  But a Hash is not mappable as a Proc.

~~~ruby
    my_hash = ->key{{
      a: 1, b: 2, c: 3, d: 4, e: 5, f: 6
    }[key]}

    my_hash[:a]
    # => 1

    [:e, :a, :b, :f, :c, :d].map(&my_hash) # hash is now mappable
    # => [5, 1, 2, 6, 3, 4]
~~~

This seems so straight forward I believe it should be part of the language itself with the `.to_proc` method call.



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

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

* [ruby-core:71404] [Ruby trunk - Feature #11653] Add to_proc on Hash
       [not found] <redmine.issue-11653.20151104025915@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2015-11-04  6:01 ` [ruby-core:71330] " nobu
@ 2015-11-09  8:03 ` matz
  2015-11-09 14:32   ` [ruby-core:71416] Unsubscribe Dan Whiteside
  2015-11-09  8:08 ` [ruby-core:71405] [Ruby trunk - Feature #11653] Add to_proc on Hash ko1
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 8+ messages in thread
From: matz @ 2015-11-09  8:03 UTC (permalink / raw)
  To: ruby-core

Issue #11653 has been updated by Yukihiro Matsumoto.

Assignee changed from Yukihiro Matsumoto to Nobuyoshi Nakada

Accepted.

Matz.


----------------------------------------
Feature #11653: Add to_proc on Hash
https://bugs.ruby-lang.org/issues/11653#change-54774

* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
Procs can be called the same way a hash is with `[]`.  But a Hash is not mappable as a Proc.

~~~ruby
    my_hash = ->key{{
      a: 1, b: 2, c: 3, d: 4, e: 5, f: 6
    }[key]}

    my_hash[:a]
    # => 1

    [:e, :a, :b, :f, :c, :d].map(&my_hash) # hash is now mappable
    # => [5, 1, 2, 6, 3, 4]
~~~

This seems so straight forward I believe it should be part of the language itself with the `.to_proc` method call.



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

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

* [ruby-core:71405] [Ruby trunk - Feature #11653] Add to_proc on Hash
       [not found] <redmine.issue-11653.20151104025915@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2015-11-09  8:03 ` [ruby-core:71404] " matz
@ 2015-11-09  8:08 ` ko1
  2016-06-24  8:34 ` [ruby-core:76135] [Ruby trunk Feature#11653] " Ruby-Lang
  2016-06-25  5:01 ` [ruby-core:76140] " duerst
  6 siblings, 0 replies; 8+ messages in thread
From: ko1 @ 2015-11-09  8:08 UTC (permalink / raw)
  To: ruby-core

Issue #11653 has been updated by Koichi Sasada.


Discussion: https://docs.google.com/document/d/1D0Eo5N7NE_unIySOKG9lVj_eyXf66BQPM4PKp7NvMyQ/pub

Feel free to continue discussion on this ticket.


----------------------------------------
Feature #11653: Add to_proc on Hash
https://bugs.ruby-lang.org/issues/11653#change-54775

* Author: Daniel P. Clark
* Status: Open
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
Procs can be called the same way a hash is with `[]`.  But a Hash is not mappable as a Proc.

~~~ruby
    my_hash = ->key{{
      a: 1, b: 2, c: 3, d: 4, e: 5, f: 6
    }[key]}

    my_hash[:a]
    # => 1

    [:e, :a, :b, :f, :c, :d].map(&my_hash) # hash is now mappable
    # => [5, 1, 2, 6, 3, 4]
~~~

This seems so straight forward I believe it should be part of the language itself with the `.to_proc` method call.



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

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

* [ruby-core:71416] Unsubscribe
  2015-11-09  8:03 ` [ruby-core:71404] " matz
@ 2015-11-09 14:32   ` Dan Whiteside
  0 siblings, 0 replies; 8+ messages in thread
From: Dan Whiteside @ 2015-11-09 14:32 UTC (permalink / raw)
  To: Ruby developers

[-- Attachment #1: Type: text/plain, Size: 11 bytes --]

Unsubscribe

[-- Attachment #2: Type: text/html, Size: 3020 bytes --]

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

* [ruby-core:76135] [Ruby trunk Feature#11653] Add to_proc on Hash
       [not found] <redmine.issue-11653.20151104025915@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2015-11-09  8:08 ` [ruby-core:71405] [Ruby trunk - Feature #11653] Add to_proc on Hash ko1
@ 2016-06-24  8:34 ` Ruby-Lang
  2016-06-25  5:01 ` [ruby-core:76140] " duerst
  6 siblings, 0 replies; 8+ messages in thread
From: Ruby-Lang @ 2016-06-24  8:34 UTC (permalink / raw)
  To: ruby-core

Issue #11653 has been updated by Jörg W Mittag.


Daniel P. Clark wrote:
> Procs can be called the same way a hash is with `[]`.  But a Hash is not mappable as a Proc.
> 
> ~~~ruby
>     my_hash = ->key{{
>       a: 1, b: 2, c: 3, d: 4, e: 5, f: 6
>     }[key]}
> 
>     my_hash[:a]
>     # => 1
> 
>     [:e, :a, :b, :f, :c, :d].map(&my_hash) # hash is now mappable
>     # => [5, 1, 2, 6, 3, 4]
> ~~~
> 
> This seems so straight forward I believe it should be part of the language itself with the `.to_proc` method call.

This is basically a subset of what I proposed a year ago in #11262. I additionally proposed that `Hash` also implement `call`. IMO, it doesn't make much sense to have one without the other: both methods basically say "hey, I'm kinda like a function", and a `Hash` is basically just a function from keys to elements. I proposed the same thing for `Array` and `Set`, which are essentially also just functions from indices to elements (`Array`) or elements to booleans (`Set`). However, so far, there has been no interest in that ticket.

----------------------------------------
Feature #11653: Add to_proc on Hash
https://bugs.ruby-lang.org/issues/11653#change-59340

* Author: Daniel P. Clark
* Status: Closed
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
Procs can be called the same way a hash is with `[]`.  But a Hash is not mappable as a Proc.

~~~ruby
    my_hash = ->key{{
      a: 1, b: 2, c: 3, d: 4, e: 5, f: 6
    }[key]}

    my_hash[:a]
    # => 1

    [:e, :a, :b, :f, :c, :d].map(&my_hash) # hash is now mappable
    # => [5, 1, 2, 6, 3, 4]
~~~

This seems so straight forward I believe it should be part of the language itself with the `.to_proc` method call.



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

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

* [ruby-core:76140] [Ruby trunk Feature#11653] Add to_proc on Hash
       [not found] <redmine.issue-11653.20151104025915@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2016-06-24  8:34 ` [ruby-core:76135] [Ruby trunk Feature#11653] " Ruby-Lang
@ 2016-06-25  5:01 ` duerst
  6 siblings, 0 replies; 8+ messages in thread
From: duerst @ 2016-06-25  5:01 UTC (permalink / raw)
  To: ruby-core

Issue #11653 has been updated by Martin Dürst.


Jörg W Mittag wrote:

> This is basically a subset of what I proposed a year ago in #11262.

Commenting on a closed issue won't help much to move an open issue forward. One thing that might help is to split Feature #11262 into smaller issues that can be discussed more easily.

> A `Hash` is basically just a function from keys to elements.

Yes. The most direct case is `Hash.new { |h, k| my_function(k) }`. :-)



----------------------------------------
Feature #11653: Add to_proc on Hash
https://bugs.ruby-lang.org/issues/11653#change-59349

* Author: Daniel P. Clark
* Status: Closed
* Priority: Normal
* Assignee: Nobuyoshi Nakada
----------------------------------------
Procs can be called the same way a hash is with `[]`.  But a Hash is not mappable as a Proc.

~~~ruby
    my_hash = ->key{{
      a: 1, b: 2, c: 3, d: 4, e: 5, f: 6
    }[key]}

    my_hash[:a]
    # => 1

    [:e, :a, :b, :f, :c, :d].map(&my_hash) # hash is now mappable
    # => [5, 1, 2, 6, 3, 4]
~~~

This seems so straight forward I believe it should be part of the language itself with the `.to_proc` method call.



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

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

end of thread, other threads:[~2016-06-25  4:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-11653.20151104025915@ruby-lang.org>
2015-11-04  2:59 ` [ruby-core:71327] [Ruby trunk - Feature #11653] [Open] Add to_proc on Hash 6ftdan
2015-11-04  5:24 ` [ruby-core:71329] [Ruby trunk - Feature #11653] " duerst
2015-11-04  6:01 ` [ruby-core:71330] " nobu
2015-11-09  8:03 ` [ruby-core:71404] " matz
2015-11-09 14:32   ` [ruby-core:71416] Unsubscribe Dan Whiteside
2015-11-09  8:08 ` [ruby-core:71405] [Ruby trunk - Feature #11653] Add to_proc on Hash ko1
2016-06-24  8:34 ` [ruby-core:76135] [Ruby trunk Feature#11653] " Ruby-Lang
2016-06-25  5:01 ` [ruby-core:76140] " duerst

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