[#118784] [Ruby master Feature#20664] Add `before` and `until` options to Enumerator.produce — "knu (Akinori MUSHA) via ruby-core" <ruby-core@...>

Issue #20664 has been reported by knu (Akinori MUSHA).

12 messages 2024/08/03

[#118791] [Ruby master Bug#20666] Segmentation fault instead of LoadError exception — "ErezGeva2@... (Erez Geva) via ruby-core" <ruby-core@...>

Issue #20666 has been reported by ErezGeva2@gmail.com (Erez Geva).

9 messages 2024/08/04

[#118811] [Ruby master Feature#20669] Add error classes to differentiate Marshal ArgumentErrors — "olleolleolle (Olle Jonsson) via ruby-core" <ruby-core@...>

Issue #20669 has been reported by olleolleolle (Olle Jonsson).

7 messages 2024/08/08

[#118844] [Ruby master Feature#20676] Pathnames aren't Comparable — "gmcgibbon (Gannon McGibbon) via ruby-core" <ruby-core@...>

SXNzdWUgIzIwNjc2IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGdtY2dpYmJvbiAoR2Fubm9uIE1jR2li

8 messages 2024/08/13

[#118879] [Ruby master Bug#20682] Slave PTY output is lost after a child process exits in macOS — "ono-max (Naoto Ono) via ruby-core" <ruby-core@...>

Issue #20682 has been reported by ono-max (Naoto Ono).

9 messages 2024/08/19

[#118932] [Ruby master Bug#20693] Dir.tmpdir should perform a real access check before warning about writability — "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" <ruby-core@...>

Issue #20693 has been reported by kjtsanaktsidis (KJ Tsanaktsidis).

9 messages 2024/08/22

[#118979] [Ruby master Feature#20705] Should "0.E-9" be a valid float value? — "kou (Kouhei Sutou) via ruby-core" <ruby-core@...>

Issue #20705 has been reported by kou (Kouhei Sutou).

11 messages 2024/08/29

[#118983] [Ruby master Bug#20706] Can't build Ruby on macOS Sonoma and Sequoia due to: ignoring duplicate libraries, archive member '/' not a mach-o file in libruby.3.3-static.a — "wkoszek (Adam Koszek) via ruby-core" <ruby-core@...>

Issue #20706 has been reported by wkoszek (Adam Koszek).

7 messages 2024/08/29

[ruby-core:118902] [Ruby master Feature#20664] Add `before` and `until` options to Enumerator.produce

From: "ufuk (Ufuk Kayserilioglu) via ruby-core" <ruby-core@...>
Date: 2024-08-19 23:51:06 UTC
List: ruby-core #118902
Issue #20664 has been updated by ufuk (Ufuk Kayserilioglu).


@matheusrich In my opinion `take_until` might be an interesting method to add, but I think we are unnecessarily complicating the example with `it` and `nil?`.

The expression is simply:
```ruby
Enumerator.produce(File, &:superclass).take_while(&:itself)
```
and it works perfectly fine and, IMO, is very readable for anyone who knows enough to reach for `Enumerable.produce` in the first place.

With respect to the original proposal in this ticket, I also find it a little awkward when Ruby methods take something callable other than blocks, but I understand the pragmatic use of the proposed `to_proc`able keyword arguments that would satisfy the majority of cases where one would reach for `Enumerable.produce`.

----------------------------------------
Feature #20664: Add `before` and `until` options to Enumerator.produce
https://bugs.ruby-lang.org/issues/20664#change-109471

* 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/


In This Thread