-// ♓🌟 Piscēs ∷ iterable.js
-// ====================================================================
-//
-// Copyright © 2023 Lady [@ Lady’s Computer].
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ iterable.js
+ *
+ * Copyright © 2023, 2025 Lady [@ Ladys Computer].
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
+ */
import { bind, call, identity } from "./function.js";
import {
* the resulting iterator.
*
* The resulting function also takes a second argument, which will be
- * used as the `this` value when calling the provided generator
+ * used as the this value when calling the provided generator
* function, if provided.
*
* ※ The returned function is an ordinary nonconstructible (arrow)
* the resulting iterator.
*
* The resulting function also takes a second argument, which will be
- * used as the `this` value when calling the provided generator
+ * used as the this value when calling the provided generator
* function, if provided.
*
* ※ The returned function is an ordinary nonconstructible (arrow)
* the resulting iterator.
*
* The resulting function also takes a second argument, which will be
- * used as the `this` value when calling the provided generator
+ * used as the this value when calling the provided generator
* function, if provided.
*
* ※ The returned function is an ordinary nonconstructible (arrow)
* the resulting iterator.
*
* The resulting function also takes a second argument, which will be
- * used as the `this` value when calling the provided generator
+ * used as the this value when calling the provided generator
* function, if provided.
*
* ※ The returned function is an ordinary nonconstructible (arrow)
* the resulting iterator.
*
* The resulting function also takes a second argument, which will be
- * used as the `this` value when calling the provided generator
+ * used as the this value when calling the provided generator
* function, if provided.
*
* ※ This iterator function iterates over characters; use
- * `arrayIteratorFunction` to iterate over code units.
+ * arrayIteratorFunction to iterate over code units.
*
* ※ The returned function is an ordinary nonconstructible (arrow)
* function which, when called with a string, returns an iterator.
* An iterator generated by an iterator function.
*
* This class provides the internal data structure of all the
- * iterator functions as well as the `::next` behaviour they all use.
+ * iterator functions as well as the `::next´ behaviour they all use.
*
* ※ This class extends the identity function to allow for arbitrary
* construction of its superclass instance based on the provided
*
* ☡ It is not possible to type·check the provided next method or
* generator function to ensure that they actually are correct and
- * appropriately callable; if they aren’t, an error will be thrown
+ * appropriately callable; if they aren¦t, an error will be thrown
* when attempting to yield the first value.
*/
constructor(
const baseIteratorNext = this.#baseIteratorNext;
const generateNext = this.#generateNext;
while (true) {
- // This function sometimes needs to repeat its processing steps
- // in the case that a generator function was provided.
+ // This function some·times needs to repeat its processing
+ // steps in the case that a generator function was provided.
//
// To avoid potentially large amounts of recursive calls, it is
// defined in a loop which will exit the first time a suitable
return { value: UNDEFINED, done: true };
} else if (nextIterator === null) {
// This iterator is not currently yielding values from the
- // provided generator function, either because it doesn’t
+ // provided generator function, either because it doesn¦t
// exist or because its values have been exhausted.
//
// Get the next value in the base iterator and either provide
continue;
} else {
// The current iterator of values has yielded another
- // value; reyield it.
+ // value.
+ //
+ // Reyield it.
return { value, done: false };
}
}
const iteratorFunction = (
makeBaseIterator,
baseIteratorNext,
+ iteratorFunctionName,
generateNext,
stringTag = "Iterator",
) => {
const prototype = makePrototype(stringTag); // intentionally cached
- return ($, thisArg = UNDEFINED) =>
- new Iterator(
- prototype,
- call(makeBaseIterator, $, []),
- baseIteratorNext,
- generateNext == null ? null : bind(generateNext, thisArg, []),
- );
+ return defineOwnProperty(
+ ($, thisArg = UNDEFINED) =>
+ new Iterator(
+ prototype,
+ call(makeBaseIterator, $, []),
+ baseIteratorNext,
+ generateNext == null
+ ? null
+ : bind(generateNext, thisArg, []),
+ ),
+ "name",
+ defineOwnDataProperty(
+ objectCreate(null),
+ "value",
+ iteratorFunctionName,
+ ),
+ );
};
return {
bind(
iteratorFunction,
UNDEFINED,
- [arrayIterator, arrayIteratorNext],
+ [arrayIterator, arrayIteratorNext, "values"],
),
"name",
defineOwnDataProperty(
return this();
},
generatorIteratorNext,
+ "yields",
],
),
"name",
bind(
iteratorFunction,
UNDEFINED,
- [mapIterator, mapIteratorNext],
+ [mapIterator, mapIteratorNext, "entries"],
),
"name",
defineOwnDataProperty(
bind(
iteratorFunction,
UNDEFINED,
- [setIterator, setIteratorNext],
+ [setIterator, setIteratorNext, "values"],
),
"name",
defineOwnDataProperty(
bind(
iteratorFunction,
UNDEFINED,
- [stringIterator, stringIteratorNext],
+ [stringIterator, stringIteratorNext, "characters"],
),
"name",
defineOwnDataProperty(