mirror of
https://github.com/langchain-ai/langgraphjs-api.git
synced 2026-07-25 05:05:21 -04:00
18 lines
421 B
TypeScript
18 lines
421 B
TypeScript
export async function gatherIterator<T>(
|
|
i: AsyncIterable<T> | Promise<AsyncIterable<T>>,
|
|
): Promise<Array<T>> {
|
|
const out: T[] = [];
|
|
for await (const item of await i) out.push(item);
|
|
return out;
|
|
}
|
|
|
|
export function findLast<T>(
|
|
lst: Array<T>,
|
|
predicate: (item: T) => boolean,
|
|
): T | undefined {
|
|
for (let i = lst.length - 1; i >= 0; i--) {
|
|
if (predicate(lst[i])) return lst[i];
|
|
}
|
|
return undefined;
|
|
}
|