From 2e9defd03ef62fbfdcb832df7affac459b39e249 Mon Sep 17 00:00:00 2001 From: Colin Caine Date: Wed, 9 Apr 2025 14:00:28 +0100 Subject: [PATCH 1/3] Name the example inf iterator of iterators sequence Calling the helper function p() is a bit confusing because the p-series is a kinda well-known infinite series (1 + 1/(2^p) + 1/(3^p) + ...) I've chosen a name from one of the references listed by the Online Encyclopedia of Integer Sequences for this sequence. https://oeis.org/A002024 As an unrelated change, I've added a link to MDN for `flatMap`, because I didn't know that it existed for iterators, or precisely what it does. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c7e575c..ff7bea3 100644 --- a/README.md +++ b/README.md @@ -56,15 +56,15 @@ We should explore how to make this more ergonomic and functional. let digits = Iterator.concat(lows, [4, 5], highs); ``` -For the (rare) case of infinite iterators of iterators, use `flatMap` with the identity function. +For the (rare) case of infinite iterators of iterators, use the existing [`flatMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/flatMap) with the identity function. ```js -function* p() { +function* self_counting_sequence_helper() { for (let n = 1;; ++n) { yield Array(n).fill(n); } } -let repeatedNats = p().flatMap(x => x); +let self_counting_sequence = self_counting_sequence_helper().flatMap(x => x) ``` ## prior art From 2f4b5a6bb4dc4daf223db28bf6f0046c407c18a9 Mon Sep 17 00:00:00 2001 From: Colin Caine Date: Wed, 9 Apr 2025 18:42:48 +0100 Subject: [PATCH 2/3] Link to spec for iterator.flatmap Co-authored-by: Michael Ficarra --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff7bea3..b182f20 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ We should explore how to make this more ergonomic and functional. let digits = Iterator.concat(lows, [4, 5], highs); ``` -For the (rare) case of infinite iterators of iterators, use the existing [`flatMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/flatMap) with the identity function. +For the (rare) case of infinite iterators of iterators, use [`Iterator.prototype.flatMap`](https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-iterator.prototype.flatmap) with the identity function. ```js function* self_counting_sequence_helper() { From 639010841b5247413ea4eebeb38a109562b049a8 Mon Sep 17 00:00:00 2001 From: Colin Caine Date: Wed, 9 Apr 2025 18:43:22 +0100 Subject: [PATCH 3/3] snakeCase --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b182f20..8e1736a 100644 --- a/README.md +++ b/README.md @@ -59,12 +59,12 @@ let digits = Iterator.concat(lows, [4, 5], highs); For the (rare) case of infinite iterators of iterators, use [`Iterator.prototype.flatMap`](https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-iterator.prototype.flatmap) with the identity function. ```js -function* self_counting_sequence_helper() { +function* selfCountingSequenceHelper() { for (let n = 1;; ++n) { yield Array(n).fill(n); } } -let self_counting_sequence = self_counting_sequence_helper().flatMap(x => x) +let selfCountingSequence = selfCountingSequenceHelper().flatMap(x => x) ``` ## prior art