import { ArrayIterator, MapIterator, ObjectIterator, SetIterator, StringIterator } from './src/types' /** * @description * Universal version of native `Array#forEach` that works on pretty much any * iterable - arrays & array-likes, objects, Sets, Maps, strings, custom * iterables, etc. * * @parameters * | name | type | description | * | :--: | :--: | ----------- | * | collection | `Iterable` | Iterable-like object to iterate over | * | fn | `Function` | Called with each iteration | * * @returns `undefined` * * @example * each([1, 2, 3], v => console.log(v)) * // -> 1 2 3 * * each('string', v => console.log(v)) * // -> s t r i n g * * each({ key: 'value', keyTwo: 'valueTwo' }, v => console.log(v)) * // -> 'value' 'valueTwo' * * each(new Set([1, 2, 3]), v => console.log(v)) * // -> 1 2 3 * * const map = new Map() * map.set('keyOne', 'valueOne') * map.set('keyTwo', 'valueTwo') * * each(map, v => console.log(v)) * // -> 'value' 'valueTwo' * * const obj = { * * [Symbol.iterator] () { * for (const n of [1, 2, 3]) { * yield n * } * } * } * * each(obj, v => console.log(v)) * // -> 1 2 3 * * @see filter * @see map * @see reduce * @since v1.0.0 * @tag collections */ interface Each { (collection: T, fn: StringIterator): void (collection: T[], fn: ArrayIterator): void (collection: Map, fn: MapIterator): void (collection: Set, fn: SetIterator): void (collection: T, fn: ObjectIterator): void } declare const each: Each export = each