Iteration Methods
Array-like iteration methods (forEach, map, filter, reduce, etc.).
forEach()
Executes a function for each entry in the pool.
pool.forEach(fn: (entry: PoolEntry<T>, index: number) => void): voidParameters:
fn- Function to execute for each entry
Example:
pool.forEach((entry, index) => {
console.log(`${index}: ${entry.data.name}`);
});map()
Maps each entry to a new value.
pool.map<U>(fn: (entry: PoolEntry<T>, index: number) => U): U[]Parameters:
fn- Function to map each entry
Returns: Array of mapped values
Example:
const names = pool.map(({ data }) => data.name);
const ips = proxyPool.map(({ data }) => data.ip);filter()
Filters entries and returns matching entries (not data).
pool.filter(fn: (entry: PoolEntry<T>, index: number) => boolean): PoolEntry<T>[]Parameters:
fn- Filter function
Returns: Array of matching entries
Example:
const active = pool.filter(({ meta }) => meta.active === true);reduce()
Reduces the pool to a single value.
pool.reduce<U>(
fn: (accumulator: U, entry: PoolEntry<T>, index: number) => U,
initialValue: U
): UParameters:
fn- Reducer functioninitialValue- Initial value for reduction
Returns: Reduced value
Example:
const totalAge = pool.reduce((sum, entry) => sum + entry.data.age, 0);
const avgAge = totalAge / pool.size;some()
Checks if any entry matches the predicate.
pool.some(fn: (entry: PoolEntry<T>, index: number) => boolean): booleanParameters:
fn- Predicate function
Returns: True if any entry matches
Example:
const hasAdult = pool.some(({ data }) => data.age >= 18);every()
Checks if all entries match the predicate.
pool.every(fn: (entry: PoolEntry<T>, index: number) => boolean): booleanParameters:
fn- Predicate function
Returns: True if all entries match
Example:
const allActive = pool.every(({ meta }) => meta.active === true);find()
Finds the first entry matching the predicate.
pool.find(fn: (entry: PoolEntry<T>, index: number) => boolean): PoolEntry<T> | undefinedParameters:
fn- Predicate function
Returns: The first matching entry or undefined
Example:
const admin = pool.find(({ data }) => data.role === 'admin');findIndex()
Finds the index of the first entry matching the predicate.
pool.findIndex(fn: (entry: PoolEntry<T>, index: number) => boolean): numberParameters:
fn- Predicate function
Returns: The index of the first matching entry or -1
Example:
const index = pool.findIndex(({ data }) => data.id === 'user123');