[ruby-core:77235] [Ruby trunk Feature#12734] `Array#flat?`
From:
ruby@...
Date:
2016-09-09 19:20:09 UTC
List:
ruby-core #77235
Issue #12734 has been updated by Herwin W.
This is pretty trivial to implement yourself:
~~~ruby
class Array
def flat?
none?{|e|e.is_a?(Array)}
end
end
[1,2,3].flat?
=> true
[1,[2,3]].flat?
=> false
~~~
I have to agree with Nobuyoshi Nakada that I don't really see the use case here.
----------------------------------------
Feature #12734: `Array#flat?`
https://bugs.ruby-lang.org/issues/12734#change-60461
* Author: Stefan Schテシテ殕er
* Status: Feedback
* Priority: Normal
* Assignee:
----------------------------------------
It might be useful to have a method that determines whether an array is flat, i.e. one-dimensional.
~~~ruby
[1, 2, 3].flat? #=> true
[1, [2, 3]].flat? #=> false
~~~
The result should be equivalent to `ary == ary.flatten` (without the overhead of actually flattening the array)
--
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>