UNPKG

855 BJavaScriptView Raw
1/**
2 * Copyright 2013-present, 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 *
10 */
11
12'use strict';
13
14/**
15 * @param {array} arr 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 */
21
22function forEachAccumulated(arr, cb, scope) {
23 if (Array.isArray(arr)) {
24 arr.forEach(cb, scope);
25 } else if (arr) {
26 cb.call(scope, arr);
27 }
28}
29
30module.exports = forEachAccumulated;
\No newline at end of file