From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=0.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 87D961F5CB for ; Wed, 2 Oct 2024 15:19:50 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=pd4OfFT3; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=pnQEInvy; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1727882358; bh=6s7WDjuJ3bbTp1oNw56fRVoztBmJ2YDETZScbKtn3tE=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=pd4OfFT3R4whwZMraccLTANrUdNRVjPbwvkGJTuwrk5Bu7q4n5jtfMcGbD+zBmLVp GvyEI0d48ZZwsy1DfOSEdYHbShRuUiGRCU96ArXGb61Bz8NfpipfX4TiP5im6kF9Nm msYBTh1wHPL0ILFSjfrdnCeLAjnGAQV6PG59Ea20= Received: from nue.mailmanlists.eu (localhost [IPv6:::1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 4999743F30 for ; Wed, 2 Oct 2024 15:19:18 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=pnQEInvy; dkim-atps=neutral Received: from s.wrqvtzvf.outbound-mail.sendgrid.net (s.wrqvtzvf.outbound-mail.sendgrid.net [149.72.126.143]) by nue.mailmanlists.eu (Postfix) with ESMTPS id CBEE841392 for ; Wed, 2 Oct 2024 15:19:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=hJZFPb4BFbHxkDRxcUiWtGASeRh/atnY9aaVlxEa8MA=; b=pnQEInvynpdYxjRC5sD+1le/G64cuG1DfnwINVFhDAEtbtx8YrxcHePxrZ4QfxqXofrt TB1Jucy+8iVVi7AkYS4I8yjEhyPqEGnqOOBCj5bPAHuInQpSzZ6bAii8f6fBAOcgeMUMk7 og9xrew+ikzw3WFYxuKeems0oSJQKz51R5KrUpGo6MTbBsRNpS1QwP6LFAePKwZo0PtE7J Fb/I8IOM3KiChkhR4etKWSvd3rNbBzBMLilslhir0QmUAPVy5UHqY8+m4Bpb5m+dtbe3SK gmAYHjiR46P5C+JwWawrM1ll2E/O39sXMjPSWNjO1EM3hiRQzpwZl9RcUynRVeog== Received: by recvd-5577bcb48c-zmczn with SMTP id recvd-5577bcb48c-zmczn-1-66FD646A-8 2024-10-02 15:19:06.090081559 +0000 UTC m=+1718550.643793371 Received: from herokuapp.com (unknown) by geopod-ismtpd-11 (SG) with ESMTP id 9CG5MEq_TyOmXY5ZyAZaUw for ; Wed, 02 Oct 2024 15:19:06.069 +0000 (UTC) Date: Wed, 02 Oct 2024 15:19:06 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 20770 X-Redmine-Issue-Author: AlexandreMagro X-Redmine-Issue-Priority: Normal X-Redmine-Sender: shuber 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-Redmine-MailingListIntegration-Message-Ids: 96042 X-SG-EID: =?us-ascii?Q?u001=2Eoe1X9F9mzi2xray9UKpOHwR+YHaZ5aEaVhI0+h2TEtcDyPMjdglUiDUTt?= =?us-ascii?Q?E3PZ2ZHOeaNFD492FvV7jbUkj=2FTYKDwI7XUjDAi?= =?us-ascii?Q?1ijQQrE9vkdb0BtFd4gu1GdHTAC4ZARc1Sif+Zb?= =?us-ascii?Q?DNr=2FlHVbkHjQpOHAzgBc8Am=2FWKF4R5J4MvzbNUr?= =?us-ascii?Q?wdtlbw16ki634lovVXQyZ50r8=2FuzpsVv7DuNNPO?= =?us-ascii?Q?j8sxvxzaDD4HO4CT01FtJaA=2Fwkdyf7B2WmzLLfZ?= =?us-ascii?Q?atkJ?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: ZBCHYZSG3HTAPCEHT77GFN5JW2BX4SXT X-Message-ID-Hash: ZBCHYZSG3HTAPCEHT77GFN5JW2BX4SXT X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:119405] [Ruby master Feature#20770] A *new* pipe operator proposal List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "shuber (Sean Huber) via ruby-core" Cc: "shuber (Sean Huber)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20770 has been updated by shuber (Sean Huber). I agree with @zverok and am not quite sold on the value of `|>` over the existing `.then{}` if we still have to explicitly specify implicit args like `it/_1/etc` (unlike elixir). I am intrigued by the `.{}` syntax though but wish it did more than behave as an alias for `.then{}`. What if `.{}` behaved more like this elixir-style syntax without implicit args? ```ruby # existing ruby syntax url .then { URI.parse(it) } .then { Net::HTTP.get(it) } .then { JSON.parse(it).fetch_keys("some", "keys") } .then { JSON.pretty_generate(it, allow_nan: false) } .then { Example.with_non_default_arg_positioning(other_object, it) } # proposed ruby syntax url .{ URI.parse } .{ Net::HTTP.get } .{ JSON.parse.fetch_keys("some", "keys") } .{ JSON.pretty_generate(allow_nan: false) } .{ Example.with_non_default_arg_positioning(other_object, self) } ``` ---------------------------------------- Feature #20770: A *new* pipe operator proposal https://bugs.ruby-lang.org/issues/20770#change-110020 * Author: AlexandreMagro (Alexandre Magro) * Status: Open ---------------------------------------- Hello, This is my first contribution here. I have seen previous discussions around introducing a pipe operator, but it seems the community didn't reach a consensus. I would like to revisit this idea with a simpler approach, more of a syntactic sugar that aligns with how other languages implement the pipe operator, but without making significant changes to Ruby's syntax. Currently, we often write code like this: ```ruby value = half(square(add(value, 3))) ``` We can achieve the same result using the `then` method: ```ruby value = value.then { add(_1, 3) }.then { square(_1) }.then { half(_1) } ``` While `then` helps with readability, we can simplify it further using the proposed pipe operator: ```ruby value = add(value, 3) |> square(_1) |> half(_1) ``` Moreover, with the upcoming `it` feature in Ruby 3.4 (#18980), the code could look even cleaner: ```ruby value = add(value, 3) |> square(it) |> half(it) ``` This proposal uses the anonymous block argument `(_1)`, and with `it`, it simplifies the code without introducing complex syntax changes. It would allow us to achieve the same results as in other languages that support pipe operators, but in a way that feels natural to Ruby, using existing constructs like `then` underneath. I believe this operator would enhance code readability and maintainability, especially in cases where multiple operations are chained together. Thank you for considering this proposal! -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/