[ruby-core:86468] [Ruby trunk Feature#14666] nil.any?{} should return false

From: eregontp@...
Date: 2018-04-06 09:27:34 UTC
List: ruby-core #86468
Issue #14666 has been updated by Eregon (Benoit Daloze).


This could maybe be achieved in user code by adding some kind of Optional/Maybe construct, which could include Enumerable.
Then it would behave either as an empty Array or an Array of one element, based on whether it contains a value.

~~~ruby
def Maybe(v)
  v.nil? ? [] : [v]
end

Maybe(method_which_might_return_nil()).any? # but also map, each, ...
~~~

----------------------------------------
Feature #14666: nil.any?{} should return false
https://bugs.ruby-lang.org/issues/14666#change-71406

* Author: eike.rb (Eike Dierks)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hi everyone at ruby/trunk

I encountered `nil.any?`

```
undefined method `any?' for nil:NilClass (NoMethodError)
```

I fully agree with all of yours,
that `nil` should be kept slim.

But than, on the other hand,
the existence quantors are well defined on `nil`.

So `nil.any?` should always return `false`

I know this might make more sense to return `NoMethodError`

But in the end `nil` is an object,
it's not a null pointer exception any more

We can actually talk with `nil`.

Back in the objc days talking to `nil` would always return `nil`,
Im not sure what happens if `nil` answers `false` to `any?`
(currently it throws an exception, code should not depend on that)

I believe `nil` is a deep concept,
and ruby got far ahead with the Nil class

I'd like to suggest that `nil.any?{}` should return false















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