# prefer-iterator-concat πŸ“ Prefer `Iterator.concat(…)` over temporary spread arrays. 🚫 This rule is _disabled_ in the following [configs](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config): βœ… `recommended`, β˜‘οΈ `unopinionated`. πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). Prefer `Iterator.concat(…)` over temporary spread arrays. `Iterator.concat()` creates one iterator from multiple iterables. In places that accept an iterable, this avoids materializing a temporary array. ## Examples ```js // ❌ const set = new Set([...foo, ...bar]); // βœ… const set = new Set(Iterator.concat(foo, bar)); ``` ```js // ❌ for (const item of [...foo, ...bar]); // βœ… for (const item of Iterator.concat(foo, bar)); ``` This rule only reports temporary arrays made entirely from spreads. Mixed arrays are intentionally ignored. ```js // βœ… new Set([first, ...rest]); ``` `Array.from(…)` and typed array `.from(…)` cases with mapper functions are reported as suggestions instead of autofixes because replacing the array literal can change when the mapper function runs. `for…of` and `yield*` cases are reported as suggestions instead of autofixes because replacing the array literal can change when later iterables are consumed. `Promise.{all,allSettled,any,race}(…)` cases are also reported as suggestions instead of autofixes because replacing the array literal can change a synchronous throw during array creation into an asynchronous rejection.