// operator/for-each.ts /* * Copyright (c) 2021-2026 Check Digit, LLC * * This code is licensed under the MIT license (see LICENSE.txt for details). */ import type { Asyncerator } from '../asyncerator.ts'; import type { Operator } from './index.ts'; /** * Similar to Array.forEach, call forEachFunction for each value in the stream. * @param forEachFunction */ export default function ( forEachFunction: (value: Input, index: number) => void, ): Operator { return async function* (iterator: Asyncerator) { let currentIndex = 0; for await (const item of iterator) { forEachFunction(item, currentIndex++); yield item; } }; }