MCPcopy Create free account
hub / github.com/freecodexyz/free-code / lastX

Function lastX

src/utils/generators.ts:3–12  ·  view source on GitHub ↗
(as: AsyncGenerator<A>)

Source from the content-addressed store, hash-verified

1const NO_VALUE = Symbol('NO_VALUE')
2
3export async function lastX<A>(as: AsyncGenerator<A>): Promise<A> {
4 let lastValue: A | typeof NO_VALUE = NO_VALUE
5 for await (const a of as) {
6 lastValue = a
7 }
8 if (lastValue === NO_VALUE) {
9 throw new Error('No items in generator')
10 }
11 return lastValue
12}
13
14export async function returnValue<A>(
15 as: AsyncGenerator<unknown, A>,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected