From ab18ef7e98d1a9ab2f08c1007e95ceba3f3f2448 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Wed, 8 Nov 2023 14:07:53 -0600 Subject: [PATCH] Express `each()` as a function We were expressing the `each()` operation as a `const` reference. Honestly, I can't recall why this was done other than some vague connection to TypeScript. However, it makes the typedocs weird because `each` is represented as a `var`, not a `function`. This switches `each()` to be a function and fixes the typedoc at the same time. --- lib/each.ts | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/lib/each.ts b/lib/each.ts index f185ad2f9..073756152 100644 --- a/lib/each.ts +++ b/lib/each.ts @@ -25,29 +25,7 @@ import { createContext } from "./context.ts"; * @param stream - the stream to iterate * @returns an operation to iterate `stream` */ -export const each = iterate as Each; - -/** - * @ignore - */ -export type Each = typeof iterate & { - /** - * Indicate that the current iteration in a for-each loop is complete. - * - * @see {@link each} - */ - next: Operation; -}; - -interface EachLoop { - subscription: Subscription; - current: IteratorResult; - stale?: true; -} - -const EachStack = createContext[]>("each"); - -function iterate(stream: Stream): Operation> { +export function each(stream: Stream): Operation> { return { *[Symbol.iterator]() { let subscription = yield* stream.subscribe(); @@ -65,7 +43,7 @@ function iterate(stream: Stream): Operation> { next() { if (context.stale) { let error = new Error( - `for each loop did not use each.next operation before continuing`, + `for each loop did not use each.next() operation before continuing`, ); error.name = "IterationError"; throw error; @@ -87,7 +65,7 @@ function iterate(stream: Stream): Operation> { }; } -iterate.next = function next() { +each.next = function next() { return { name: "each.next()", *[Symbol.iterator]() { @@ -107,3 +85,11 @@ iterate.next = function next() { }, } as Operation; }; + +interface EachLoop { + subscription: Subscription; + current: IteratorResult; + stale?: true; +} + +const EachStack = createContext[]>("each");