1/** 2 * Copyright 2013-2014, Facebook, Inc. 3 * All rights reserved. 4 * 5 * This source code is licensed under the BSD-style license found in the 6 * LICENSE file in the root directory of this source tree. An additional grant 7 * of patent rights can be found in the PATENTS file in the same directory. 8 * 9 * @providesModule forEachAccumulated 10 */ 11 12"use strict"; 13 14/** 15 * @param {array} an "accumulation" of items which is either an Array or 16 * a single item. Useful when paired with the `accumulate` module. This is a 17 * simple utility that allows us to reason about a collection of items, but 18 * handling the case when there is exactly one item (and we do not need to 19 * allocate an array). 20 */ 21var forEachAccumulated = function(arr, cb, scope) { 22 if (Array.isArray(arr)) { 23 arr.forEach(cb, scope); 24 } else if (arr) { 25 cb.call(scope, arr); 26 } 27}; 28 29module.exports = forEachAccumulated; 30 31