packages/shared/util/Recoil_concatIterables.js (11 lines of code) (raw):
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails oncall+recoil
* @flow strict
* @format
*/
'use strict';
/**
* Combines multiple Iterables into a single Iterable.
* Traverses the input Iterables in the order provided and maintains the order
* of their elements.
*
* Example:
* ```
* const r = Array.from(concatIterables(['a', 'b'], ['c'], ['d', 'e', 'f']));
* r == ['a', 'b', 'c', 'd', 'e', 'f'];
* ```
*/
function* concatIterables<TValue>(
iters: Iterable<Iterable<TValue>>,
): Iterable<TValue> {
for (const iter of iters) {
for (const val of iter) {
yield val;
}
}
}
module.exports = concatIterables;