ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:73824] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
@ 2016-02-16  8:08 ` naruse
  2016-02-16  8:30 ` [ruby-core:73826] " muraken
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: naruse @ 2016-02-16  8:08 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been reported by Yui NARUSE.

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73826] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
  2016-02-16  8:08 ` [ruby-core:73824] [Ruby trunk Feature#12075] some container#nonempty? naruse
@ 2016-02-16  8:30 ` muraken
  2016-02-16  8:31 ` [ruby-core:73827] " akr
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: muraken @ 2016-02-16  8:30 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Kenta Murata.


How about `ary.include_something?` ?

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57002

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73827] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
  2016-02-16  8:08 ` [ruby-core:73824] [Ruby trunk Feature#12075] some container#nonempty? naruse
  2016-02-16  8:30 ` [ruby-core:73826] " muraken
@ 2016-02-16  8:31 ` akr
  2016-02-16  8:52 ` [ruby-core:73830] " sawadatsuyoshi
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: akr @ 2016-02-16  8:31 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Akira Tanaka.


How about "some?".


----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57003

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73830] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2016-02-16  8:31 ` [ruby-core:73827] " akr
@ 2016-02-16  8:52 ` sawadatsuyoshi
  2016-02-16 10:02 ` [ruby-core:73838] " rr.rosas
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: sawadatsuyoshi @ 2016-02-16  8:52 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Tsuyoshi Sawada.


That is a use case for Rails' `blank?`.

~~~RUBY
class Object
  def blank?
    respond_to?(:empty?) ? !!empty? : !self
  end
end

unless ary.blank?
  #  some code
end
~~~


----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57007

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73838] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2016-02-16  8:52 ` [ruby-core:73830] " sawadatsuyoshi
@ 2016-02-16 10:02 ` rr.rosas
  2016-02-16 14:17 ` [ruby-core:73846] " shyouhei
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: rr.rosas @ 2016-02-16 10:02 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Rodrigo Rosenfeld Rosas.


+1 for bringing blank? and present? to Ruby core. I often use (a || '').empty? checks for not having to depend on ActiveSupport directly in my Ruby code. I'd love to see them in Ruby core though. 

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57014

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73846] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2016-02-16 10:02 ` [ruby-core:73838] " rr.rosas
@ 2016-02-16 14:17 ` shyouhei
  2016-02-16 15:28 ` [ruby-core:73848] " sawadatsuyoshi
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: shyouhei @ 2016-02-16 14:17 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Shyouhei Urabe.


No, the OP wants to detect things that are _not_ empty.  This is not what blank? means.  Also note that blank? in ActiveSupport has different (far more Rails-centric) semantics than what is described in #3.

https://github.com/rails/rails/blob/b3eac823006eb6a346f88793aabef28a6d4f928c/activesupport/lib/active_support/core_ext/object/blank.rb#L115

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57019

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73848] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2016-02-16 14:17 ` [ruby-core:73846] " shyouhei
@ 2016-02-16 15:28 ` sawadatsuyoshi
  2016-02-16 17:30 ` [ruby-core:73852] " rr.rosas
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: sawadatsuyoshi @ 2016-02-16 15:28 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Tsuyoshi Sawada.


Regarding the first point:

Shyouhei Urabe wrote:
> No, the OP wants to detect things that are _not_ empty.  This is not what blank? means.

Yes, I meant that `blank?` is the opposite of what OP wants. `present?` is what the OP wants.

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57021

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73852] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2016-02-16 15:28 ` [ruby-core:73848] " sawadatsuyoshi
@ 2016-02-16 17:30 ` rr.rosas
  2016-02-16 22:12   ` [ruby-core:73857] " Matthew Kerwin
  2016-02-19 23:10 ` [ruby-core:73900] " shevegen
                   ` (11 subsequent siblings)
  19 siblings, 1 reply; 21+ messages in thread
From: rr.rosas @ 2016-02-16 17:30 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Rodrigo Rosenfeld Rosas.


The implementation doesn't have to be the same as the one implemented by ActiveSupport. I think it would be fine to simply check for nil? and empty?. But I'd like to keep the names present? and blank? anyway.

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57025

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73857] Re: [Ruby trunk Feature#12075] some container#nonempty?
  2016-02-16 17:30 ` [ruby-core:73852] " rr.rosas
@ 2016-02-16 22:12   ` Matthew Kerwin
  0 siblings, 0 replies; 21+ messages in thread
From: Matthew Kerwin @ 2016-02-16 22:12 UTC (permalink / raw
  To: Ruby developers


[-- Attachment #1.1: Type: text/plain, Size: 569 bytes --]

On 17/02/2016 3:31 AM, <rr.rosas@gmail.com> wrote:
>
> Issue #12075 has been updated by Rodrigo Rosenfeld Rosas.
>
>
> The implementation doesn't have to be the same as the one implemented by
ActiveSupport. I think it would be fine to simply check for nil? and
empty?. But I'd like to keep the names present? and blank? anyway.
>

I'm sure the rails community would love methods with identical names but
different behaviours to suddenly appear in the core.

Personally I don't have a problem with 'nonempty?', since that's the
trinary complement of 'empty' and 'full'.

[-- Attachment #1.2: Type: text/html, Size: 755 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]


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

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

* [ruby-core:73900] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2016-02-16 17:30 ` [ruby-core:73852] " rr.rosas
@ 2016-02-19 23:10 ` shevegen
  2016-02-25  2:47 ` [ruby-core:73968] " shyouhei
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: shevegen @ 2016-02-19 23:10 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Robert A. Heiler.


Perhaps the name .contains? might be good?

Although, .include? sort of is more or less synonymous with .contains? so perhaps this is not a good choice either.

.nonempty? seems a bit long, .non_empty? would be even longer :)

.empty? is a very good name already, I am not sure if "! .empty?" has a good name, though ruby uses the keyword "not"
already. Could use .notempty? haha sorry, I have no good suggestion for a fitting name for negation either, but I am
totally fine with the idea and functionality of the proposal itself, it's a good one.

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57061

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73968] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2016-02-19 23:10 ` [ruby-core:73900] " shevegen
@ 2016-02-25  2:47 ` shyouhei
  2016-02-25  5:12 ` [ruby-core:73969] " sawadatsuyoshi
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: shyouhei @ 2016-02-25  2:47 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Shyouhei Urabe.


I have just learned that zsh(1) calls this concept being "full". http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Qualifiers

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57121

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73969] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2016-02-25  2:47 ` [ruby-core:73968] " shyouhei
@ 2016-02-25  5:12 ` sawadatsuyoshi
  2016-02-25 16:37 ` [ruby-core:73988] " rr.rosas
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: sawadatsuyoshi @ 2016-02-25  5:12 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Tsuyoshi Sawada.


What about introducing `NilClass#empty?`:

~~~RUBY
nil.empty? # => true
~~~

The code in question can be written simply as:

~~~RUBY
unless ary.empty?
  #  some code
end
~~~

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57122

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73988] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2016-02-25  5:12 ` [ruby-core:73969] " sawadatsuyoshi
@ 2016-02-25 16:37 ` rr.rosas
  2016-02-26  4:33 ` [ruby-core:73998] " nobu
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: rr.rosas @ 2016-02-25 16:37 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Rodrigo Rosenfeld Rosas.


I like this idea a lot, Tsuyoshi. I'm +1 for introducing nil?.empty? as returning true.

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57141

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73998] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2016-02-25 16:37 ` [ruby-core:73988] " rr.rosas
@ 2016-02-26  4:33 ` nobu
  2016-02-26  4:40 ` [ruby-core:73999] " nobu
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: nobu @ 2016-02-26  4:33 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Nobuyoshi Nakada.


First, along this line, we'll need negative forms for all predicate methods.

And I think `nil.empty?` makes no sense.

Just an idea:

```ruby
module Kernel
  def not(*a)
    not a.empty? ? self : !__send__(*a)
  end
end

ary = nil;   ary&.not(:empty?) #=> nil
ary = [];    ary&.not(:empty?) #=> false
ary = [nil]; ary&.not(:empty?) #=> true
```




----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57152

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:73999] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2016-02-26  4:33 ` [ruby-core:73998] " nobu
@ 2016-02-26  4:40 ` nobu
  2016-02-26  5:22 ` [ruby-core:74000] " matthew
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: nobu @ 2016-02-26  4:40 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Nobuyoshi Nakada.


Or

```ruby
module Kernel
  def !(*a)
    a.empty? ? super() : !__send__(*a)
  end
end

ary = nil;   ary&.!:empty? #=> nil
ary = [];    ary&.!:empty? #=> false
ary = [nil]; ary&.!:empty? #=> true
```

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57153

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:74000] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (13 preceding siblings ...)
  2016-02-26  4:40 ` [ruby-core:73999] " nobu
@ 2016-02-26  5:22 ` matthew
  2016-02-26  7:25 ` [ruby-core:74002] " nobu
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: matthew @ 2016-02-26  5:22 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Matthew Kerwin.


Nobuyoshi Nakada wrote:
> First, along this line, we'll need negative forms for all predicate methods.
> 
> And I think `nil.empty?` makes no sense.
> 
> Just an idea:
> 
> ```ruby
> module Kernel
>   def not(*a)
>     not a.empty? ? self : __send__(*a)
>   end
> end
> 
> ary = nil;   ary&.not(:empty?) #=> nil
> ary = [];    ary&.not(:empty?) #=> false
> ary = [nil]; ary&.not(:empty?) #=> true
> ```

I like this proposal. I definitely prefer the word 'not' over the symbol '!', because `ary&.!:empty?` has too much consecutive punctuation for my eyes.

Would there be value in extending it to accept a block?

```ruby
module Kernel
  def not(*a, &b)
    not a.empty? ? self : __send__(*a, &b)
    # or even:
    #not a.empty? ? (b ? yield self : self) : __send__(*a, &b)
  end
end

ary = [];  ary&.not(:any?){|x|x>0} #=> true
ary = [1]; ary&.not(:any?){|x|x>0} #=> false
```

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57154

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:74002] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (14 preceding siblings ...)
  2016-02-26  5:22 ` [ruby-core:74000] " matthew
@ 2016-02-26  7:25 ` nobu
  2016-02-26  9:31 ` [ruby-core:74005] " eregontp
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: nobu @ 2016-02-26  7:25 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Nobuyoshi Nakada.


https://github.com/ruby/ruby/compare/trunk...nobu:feature/12075-not

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57157

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:74005] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (15 preceding siblings ...)
  2016-02-26  7:25 ` [ruby-core:74002] " nobu
@ 2016-02-26  9:31 ` eregontp
  2016-05-17  7:31 ` [ruby-core:75548] " nobu
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: eregontp @ 2016-02-26  9:31 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Benoit Daloze.


Nobuyoshi Nakada wrote:
> https://github.com/ruby/ruby/compare/trunk...nobu:feature/12075-not

I like it!

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-57159

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:
* String
* Array
* Hash



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

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

* [ruby-core:75548] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (16 preceding siblings ...)
  2016-02-26  9:31 ` [ruby-core:74005] " eregontp
@ 2016-05-17  7:31 ` nobu
  2016-05-17  9:26 ` [ruby-core:75558] [Ruby trunk Feature#12075][Feedback] " naruse
  2016-09-26 18:27 ` [ruby-core:77412] [Ruby trunk Feature#12075] " her
  19 siblings, 0 replies; 21+ messages in thread
From: nobu @ 2016-05-17  7:31 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Nobuyoshi Nakada.

Description updated

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-58679

* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```ruby
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:

* String
* Array
* Hash



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

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

* [ruby-core:75558] [Ruby trunk Feature#12075][Feedback] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (17 preceding siblings ...)
  2016-05-17  7:31 ` [ruby-core:75548] " nobu
@ 2016-05-17  9:26 ` naruse
  2016-09-26 18:27 ` [ruby-core:77412] [Ruby trunk Feature#12075] " her
  19 siblings, 0 replies; 21+ messages in thread
From: naruse @ 2016-05-17  9:26 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by Yui NARUSE.

Status changed from Assigned to Feedback

Array#any? seems to work usual use cases.
Feedback if another cases are discovered.

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-58692

* Author: Yui NARUSE
* Status: Feedback
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```ruby
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:

* String
* Array
* Hash



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

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

* [ruby-core:77412] [Ruby trunk Feature#12075] some container#nonempty?
       [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
                   ` (18 preceding siblings ...)
  2016-05-17  9:26 ` [ruby-core:75558] [Ruby trunk Feature#12075][Feedback] " naruse
@ 2016-09-26 18:27 ` her
  19 siblings, 0 replies; 21+ messages in thread
From: her @ 2016-09-26 18:27 UTC (permalink / raw
  To: ruby-core

Issue #12075 has been updated by sorah Shota Fukumori.


I know any? works on some use cases, but I'm positive to have a proposed method because using `any?` has a pitfall. We have to guarantee an array doesn't have only false or nil. Also I'm worrying users who started to use `any?` for this use case, but doesn't know this pitfall.

I'm positive on Object#not idea.

----------------------------------------
Feature #12075: some container#nonempty?
https://bugs.ruby-lang.org/issues/12075#change-60668

* Author: Yui NARUSE
* Status: Feedback
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I sometimes write following code.

```ruby
ary = some_metho_returns_nil_or_empty_container() # nil or "" or [] or {}

if ary && !ary.empty?
  #  some code
end
```

But the condition `ary && !ary.empty?` is too long and complex.
Though Ruby 2.3 introduces `&.`, but this can’t be written as `ary&.empty?`.

One idea is add `nonempty?` write as `ary&.nonempty?`.

akr: `nonempty?` is not good name because human is not good at handling 

This discussion matches following core classes:

* String
* Array
* Hash



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

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

end of thread, other threads:[~2016-09-26 17:55 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-12075.20160216080828@ruby-lang.org>
2016-02-16  8:08 ` [ruby-core:73824] [Ruby trunk Feature#12075] some container#nonempty? naruse
2016-02-16  8:30 ` [ruby-core:73826] " muraken
2016-02-16  8:31 ` [ruby-core:73827] " akr
2016-02-16  8:52 ` [ruby-core:73830] " sawadatsuyoshi
2016-02-16 10:02 ` [ruby-core:73838] " rr.rosas
2016-02-16 14:17 ` [ruby-core:73846] " shyouhei
2016-02-16 15:28 ` [ruby-core:73848] " sawadatsuyoshi
2016-02-16 17:30 ` [ruby-core:73852] " rr.rosas
2016-02-16 22:12   ` [ruby-core:73857] " Matthew Kerwin
2016-02-19 23:10 ` [ruby-core:73900] " shevegen
2016-02-25  2:47 ` [ruby-core:73968] " shyouhei
2016-02-25  5:12 ` [ruby-core:73969] " sawadatsuyoshi
2016-02-25 16:37 ` [ruby-core:73988] " rr.rosas
2016-02-26  4:33 ` [ruby-core:73998] " nobu
2016-02-26  4:40 ` [ruby-core:73999] " nobu
2016-02-26  5:22 ` [ruby-core:74000] " matthew
2016-02-26  7:25 ` [ruby-core:74002] " nobu
2016-02-26  9:31 ` [ruby-core:74005] " eregontp
2016-05-17  7:31 ` [ruby-core:75548] " nobu
2016-05-17  9:26 ` [ruby-core:75558] [Ruby trunk Feature#12075][Feedback] " naruse
2016-09-26 18:27 ` [ruby-core:77412] [Ruby trunk Feature#12075] " her

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