ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: samuel@oriontransfer.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:91537] [Ruby trunk Feature#7394] Enumerable#find ifnone parameter could be non-callable
Date: Wed, 13 Feb 2019 22:08:55 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-76794.20190213220853.64191269cb631630@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-7394.20121119123644@ruby-lang.org

Issue #7394 has been updated by ioquatix (Samuel Williams).


Just because it might cause some surprise, perhaps we can use keyword argument for this.

e.g.

```ruby
a = [1, 2, 3]
a.find(else: 0) { |x| x > 3 } #=> 0
```

I kind of prefer original suggestion, but I can imagine if passing an object that responds to `#call` it might have unexpected behaviour.

----------------------------------------
Feature #7394: Enumerable#find ifnone parameter could be non-callable
https://bugs.ruby-lang.org/issues/7394#change-76794

* Author: zzak (Zachary Scott)
* Status: Assigned
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
----------------------------------------
=begin
from github:
https://github.com/ruby/ruby/pull/186

In trunk the Enumerable #find method ifnone parameter has to be callable or nil. I found that sometimes I want to return a simple value without wrapping it in a proc. This pull request adds support for non-callable defaults when no items match.

(({a = [1, 2, 3]}))

The current behavior
(({a.find(proc { :foo }) { |x| x > 3 } #=> :foo}))

With patch
(({a.find(0) { |x| x > 3 } #=> 0}))
=end


---Files--------------------------------
enumerable_find_noncallable.patch (3.45 KB)


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

  parent reply	other threads:[~2019-02-13 22:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-19  3:36 [ruby-core:49557] [ruby-trunk - Feature #7394][Open] Enumerable#find ifnone parameter could be non-callable zzak (Zachary Scott)
2012-11-24  2:02 ` [ruby-core:49963] [ruby-trunk - Feature #7394][Assigned] " mame (Yusuke Endoh)
2012-11-24  2:09 ` [ruby-core:49966] [ruby-trunk - Feature #7394] " mame (Yusuke Endoh)
2012-11-24  3:16 ` [ruby-core:49990] " zzak (Zachary Scott)
2019-02-13 22:06 ` [ruby-core:91536] [Ruby trunk Feature#7394] " samuel
2019-02-13 22:08 ` samuel [this message]
2019-02-14  4:44 ` [ruby-core:91542] " nobu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-76794.20190213220853.64191269cb631630@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).