[#83096] File.setuid? on IO (Re: [ruby-cvs:67289] normal:r60108 (trunk): file.c: release GVL in File.{setuid?, setgid?, sticky?}) — Nobuyoshi Nakada <nobu@...>
On 2017/10/04 8:47, [email protected] wrote:
5 messages
2017/10/04
[#83100] Re: File.setuid? on IO (Re: [ruby-cvs:67289] normal:r60108 (trunk): file.c: release GVL in File.{setuid?, setgid?, sticky?})
— Eric Wong <normalperson@...>
2017/10/04
Nobuyoshi Nakada <[email protected]> wrote:
[#83105] Re: File.setuid? on IO (Re: [ruby-cvs:67289] normal:r60108 (trunk): file.c: release GVL in File.{setuid?, setgid?, sticky?})
— Nobuyoshi Nakada <nobu@...>
2017/10/04
On 2017/10/04 15:55, Eric Wong wrote:
[#83107] Alias Enumerable#include? to Enumerable#includes? — Alberto Almagro <albertoalmagro@...>
Hello,
9 messages
2017/10/04
[#83113] Re: Alias Enumerable#include? to Enumerable#includes?
— "Urabe, Shyouhei" <shyouhei@...>
2017/10/05
This has been requested countless times, then rejected each and every time.
[#83129] Re: Alias Enumerable#include? to Enumerable#includes?
— Alberto Almagro <albertoalmagro@...>
2017/10/05
Sorry I didn't found it on the core mail list's archive.
[#83138] Re: Alias Enumerable#include? to Enumerable#includes?
— "Urabe, Shyouhei" <shyouhei@...>
2017/10/06
Ruby has not been made of popular votes so far. You have to show us
[#83149] Re: Alias Enumerable#include? to Enumerable#includes?
— Eric Wong <normalperson@...>
2017/10/06
Alberto Almagro <[email protected]> wrote:
[#83200] [Ruby trunk Feature#13996] [PATCH] file.c: apply2files releases GVL — normalperson@...
Issue #13996 has been reported by normalperson (Eric Wong).
4 messages
2017/10/10
[ruby-core:83287] [Ruby trunk Bug#14015] Enumerable & Hash yielding arity
From:
nobu@...
Date:
2017-10-15 01:21:02 UTC
List:
ruby-core #83287
Issue #14015 has been updated by nobu (Nobuyoshi Nakada).
Description updated
We know, but can't fix for backward compatibilities, now.
----------------------------------------
Bug #14015: Enumerable & Hash yielding arity
https://bugs.ruby-lang.org/issues/14015#change-67245
* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
* ruby -v: 2.5.0 preview 1
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
The subtle difference between `yield 1, 2` and `yield [1, 2]` has always confused me.
Today I wanted to pass a method to Hash#flat_map and realized how it's even more confusing than I thought.
I assumed that `Hash#each` was calling `yield key, value`. But somehow it's not that simple:
~~~ ruby
{a: 1}.map(&->(key, value){}) # => [nil]
{a: 1}.flat_map(&->(key, value){}) #=> ArgumentError: wrong number of arguments (given 1, expected 2)
~~~
What blows my mind, is that a custom method `each` that does `yield a, 1` has different result!
~~~ ruby
class << o = Object.new
include Enumerable
def each
yield :a, 1
end
end
o.map(&->(key, value){}) # => [nil]
o.flat_map(&->(key, value){}) # => [nil] does not raise!!
~~~
I don't even know how that's possible, since Hash doesn't have a specialized `flat_map` method...
Here's a list of methods that accept a lambda of arity 2 (as I would expect)
For Hash
each, any?, map, select, reject,
For a custom yield
each, any?, map, count, find_index, flat_map, all?, one?, none?, take_while, uniq
These two lists have `each`, `map` and `any?` in common. Others work in one flavor, not the other. Many require arity 1: find, sort_by, grep, grep_v, count, detect, find_index, find_all, ...
To make things even more impossible, `Hash#map` has been working with arity 2 since Ruby 2.4 only.
Finally, `Hash#each` changes the expected arity of `select`, `reject`, and `any?`, but not of `map`:
~~~ruby
{a: 1} .select(&->(a, b){}) # => {}
{a: 1}.each.select(&->(a, b){}) # => wrong number of arguments (given 1, expected 2)
~~~
Conclusion:
It seems more or less impossible to guess the expected arity of methods of Enumerable and of Hash, and they are not even consistent with one another. This makes these methods more or less unusable with lambdas.
While compatibility could be an issue, the fact that `Hash#map` has changed it's arity (I believe following https://bugs.ruby-lang.org/issues/13391 ) makes me think that compatibility with the lesser used methods would be even less of a problem.
My personal wish: that the following methods be fixed to expect arity 2 for lambdas:
For both Hash & Enumerable:
* find, sort_by, grep, grep_v, detect, find_all, partition, group_by, min_by, max_by, minmax_by, reverse_each, drop_while, sum
For Hash:
* count, find_index, flat_map, all?, one?, none?, take_while, uniq
For Enumerable:
* select, reject
Matz, what do you think?
---Files--------------------------------
yield_arity.rb (805 Bytes)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>