From: ko1@atdot.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:93967] [Ruby master Feature#15829] Object#then_if(condition){}
Date: Mon, 29 Jul 2019 06:58:42 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-80158.20190729065841.d2936cc246780bc7@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15829.20190505182618@ruby-lang.org
Issue #15829 has been updated by ko1 (Koichi Sasada).
Status changed from Open to Rejected
It seems difficult to introduce.
if you are interest about this ticket yet, could you reopen it and file on our dev-meeting agenda?
https://bugs.ruby-lang.org/issues/15996
Thanks.
----------------------------------------
Feature #15829: Object#then_if(condition){}
https://bugs.ruby-lang.org/issues/15829#change-80158
* Author: foonlyboy (Eike Dierks)
* Status: Rejected
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I'd like to propose some sugar to Object#then
There should be `Object#then_if(condition, &block)`
The block should only be applied when the condition is true,
otherwise the object should be returned without applying the block.
Rationale:
I frequently use `Object#then` with Rails to extend queries like this:
```ruby
foo.then {|query|
if(condition)
query.where(zip:zap)
else
query
end
}
```
by using the proposed `Object#then_if` the example could be simplified to:
```ruby
foo.then_if(condition) {|query|
query.where(zip:zap)
}
```
I believe that this also applies to a lot of other use cases,
i.e. only applying some transformation if some condition is true,
but otherwise leaving the result untouched.
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2019-07-29 6:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-15829.20190505182618@ruby-lang.org>
2019-05-05 18:26 ` [ruby-core:92559] [Ruby trunk Feature#15829] Object#then_if(condition){} foonlyboy
2019-05-05 18:35 ` [ruby-core:92560] " foonlyboy
2019-05-05 18:48 ` [ruby-core:92561] " foonlyboy
2019-05-05 20:30 ` [ruby-core:92564] " foonlyboy
2019-05-05 20:51 ` [ruby-core:92565] " sawadatsuyoshi
2019-05-11 7:13 ` [ruby-core:92620] " nobu
2019-05-11 12:11 ` [ruby-core:92621] " sawadatsuyoshi
2019-07-29 6:58 ` ko1 [this message]
2019-12-15 8:22 ` [ruby-core:96245] [Ruby master " masafumi.o1988
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-80158.20190729065841.d2936cc246780bc7@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).