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=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 8C4721F47A for ; Mon, 26 Aug 2024 16:14:08 +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=eEB3zMBA; 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=H4GM+4Py; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1724688845; bh=T+oDsvvm9nQtjxaihcdxHfzrnDvTV50mHU6tynul6AI=; 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=eEB3zMBAB5y5TS29NIMSO8zr0JqTO0xTn87nAxMZD+u5F8ywuWphO+299A2RATR8i Zo3aU7aGPoAdQEFkP9fkl3IC7nwqgjQl6nf7wbFlVyeot3tPBnedT7Ix7qIxXgtoI/ g0o3smb3F0aIaxb64eYTayha0gQwmtGcycsnCRZY= Received: from nue.mailmanlists.eu (localhost [IPv6:::1]) by nue.mailmanlists.eu (Postfix) with ESMTP id AEDC743D9F for ; Mon, 26 Aug 2024 16:14:05 +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=H4GM+4Py; dkim-atps=neutral Received: from s.wrqvtbkv.outbound-mail.sendgrid.net (s.wrqvtbkv.outbound-mail.sendgrid.net [149.72.123.24]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 0291543CA5 for ; Mon, 26 Aug 2024 16:13:53 +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=MIYb8SS7mftjLonXesWF9gqc5BNOAkKc/YKQ8ObcHSw=; b=H4GM+4Pyf1kVqSVZX4ZFlHwE7pvKLacftKmTE8vG9tWZoTjlxdMyzJ2TvWKKeqqfZGK2 ctqt/D+Yj74szsHweipIOYy8HDK0eutaTPsKX5uYeiJMuTDeY8cSr7l2duxMgdIcidf9vv R9N1l6q4jIYm812PfXQ+b0SdsWwg4zuaQVomfic1qi9dYuNJpTeIUd8IIXb9zulxUqhRdh i5W8cR99pKiLHJi5ltO6uXny3eKsk2xzOdUwX1WdCtsDHDjbu75vmadixdWV3ocypzaRi0 UVQAFUbVGRtpgAanInJ4QRNqMN4Qoqe8Gwt2r5oHjor7VtO0BVy33tOA7T1fcTbQ== Received: by recvd-6c5668c69-7llwl with SMTP id recvd-6c5668c69-7llwl-1-66CCA9C0-3C 2024-08-26 16:13:52.957575667 +0000 UTC m=+410446.667616541 Received: from herokuapp.com (unknown) by geopod-ismtpd-22 (SG) with ESMTP id -A0XBYyIT_2AIsrllFqjVw for ; Mon, 26 Aug 2024 16:13:52.938 +0000 (UTC) Date: Mon, 26 Aug 2024 16:13:52 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 20664 X-Redmine-Issue-Author: knu X-Redmine-Issue-Priority: Normal X-Redmine-Sender: Eregon 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: 95598 X-SG-EID: =?us-ascii?Q?u001=2EByjZWvxTCjdoV8K03xEuhE7KqN4thWULFLM7+oH78KY30oYB3qFthsDpL?= =?us-ascii?Q?4w4cbYa3ttBh8bAHPOnE=2FkzPba67JNu7Lnrked2?= =?us-ascii?Q?O7K9VQ=2FJax0MjPrYCcwur70+Z1BOKxw964QTNB8?= =?us-ascii?Q?UcIa3=2FND9LWYsZIFsagRs8SdEaYjsxjoVXb55ii?= =?us-ascii?Q?ckwtfu5wqh8jv8FyN974B6elKtbd+YiD5U7KYi+?= =?us-ascii?Q?yTzBFdGEAuxCCqY6yqg32zzimH7QyYzgp3=2F5ohj?= =?us-ascii?Q?UFuBei3eyutmJw2K0f5aUwYNMw=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: DBREEEIVXJ2EHUCJWSWV3PB4IP5L5K5E X-Message-ID-Hash: DBREEEIVXJ2EHUCJWSWV3PB4IP5L5K5E 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:118962] [Ruby master Feature#20664] Add `before` and `until` options to Enumerator.produce List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "Eregon (Benoit Daloze) via ruby-core" Cc: "Eregon (Benoit Daloze)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20664 has been updated by Eregon (Benoit Daloze). I think that makes sense, as an opposite of `take_while`: * `take_while` takes all elements until the block returns falsy, and does not include that element which yielded falsy. * `take_until` takes all elements until the block returns truthy, and does not include that element which yielded truthy. If clearly documented that probably solves most of the confusion. So +1 from me to add `take_until`. I wonder if there is value in having variants that do include the element that stops, but at least so far in the linked issues there seems to be no such use-case. ---------------------------------------- Feature #20664: Add `before` and `until` options to Enumerator.produce https://bugs.ruby-lang.org/issues/20664#change-109534 * Author: knu (Akinori MUSHA) * Status: Open ---------------------------------------- Enumerator.produce provides a nice way to generate an infinite sequence but is a bit awkward to define how to end a sequence. It lacks a simple and easy way to produce typical finite sequences in an intuitive syntax. This proposal attempts to solve the problem by adding these two options to the method: - `before`: when provided, it is used as a predicate to determine if an iteration should end before a generated value gets yielded. - `until`: when provided, it is used as a predicate to determine if an iteration should end until after a generated value gets yielded. Any value that responds to `to_proc` and returns a `Proc` object is accepted in these options. A typical use case for the `before` option is traversing a tree structure to iterate over the ancestors or following/preceding siblings of a node. The `until` option can be used when there is a clear definition of the "last" value to yield. ```ruby enum = Enumerator.produce(File, before: :nil?, &:superclass) enum.to_a #=> [File, IO, Object, BasicObject] enum = Enumerator.produce(3, until: :zero?, &:pred) enum_to_a #=> [3, 2, 1, 0] ``` ---Files-------------------------------- 0001-Add-before-and-until-options-to-Enumerator.produce.patch (10.7 KB) -- 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/