packages/shared/util/Recoil_mergeMaps.js (15 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-local * @format */ 'use strict'; function mergeMaps<TKey, TValue>( ...maps: $ReadOnlyArray<$ReadOnlyMap<TKey, TValue>> ): Map<TKey, TValue> { const result = new Map(); for (let i = 0; i < maps.length; i++) { const iterator = maps[i].keys(); let nextKey; while (!(nextKey = iterator.next()).done) { // $FlowFixMe[incompatible-call] - map/iterator knows nothing about flow types result.set(nextKey.value, maps[i].get(nextKey.value)); } } /* $FlowFixMe[incompatible-return] (>=0.66.0 site=www,mobile) This comment * suppresses an error found when Flow v0.66 was deployed. To see the error * delete this comment and run Flow. */ return result; } module.exports = mergeMaps;