From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 9E0111F462 for ; Mon, 29 Jul 2019 06:58:52 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id CEC33120997; Mon, 29 Jul 2019 15:58:44 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 1D15612097E for ; Mon, 29 Jul 2019 15:58:42 +0900 (JST) Received: by filter0044p3iad2.sendgrid.net with SMTP id filter0044p3iad2-23844-5D3E9922-3 2019-07-29 06:58:42.098625943 +0000 UTC m=+215482.741427849 Received: from herokuapp.com (unknown [3.80.72.87]) by ismtpd0020p1iad2.sendgrid.net (SG) with ESMTP id WsImNCgzRMmmKnsnrUsEig for ; Mon, 29 Jul 2019 06:58:42.078 +0000 (UTC) Date: Mon, 29 Jul 2019 06:58:42 +0000 (UTC) From: ko1@atdot.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 69472 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15829 X-Redmine-Issue-Author: foonlyboy X-Redmine-Sender: ko1 X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?fVTMYOBjtdvXNcWwrscBhLsHItUXVK5L4mtnq0mdcRcyc89dxH=2FgsoqpY8PCr2?= =?us-ascii?Q?081vd1UXb=2FDdhZQ3HqjPVOvPXE4mhtWh785+5Y3?= =?us-ascii?Q?l+FRmPPWq0zO4pkgvCAUdDTtD3pAp2QQWTxzzzJ?= =?us-ascii?Q?wbIDVGBE2V2AQ2P=2FGq6OTK0BGG1Z9JG7kDdEHX6?= =?us-ascii?Q?56diSK+QUhM1c?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 93967 Subject: [ruby-core:93967] [Ruby master Feature#15829] Object#then_if(condition){} X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" 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/