1 | /**
|
2 | * Copyright (c) 2013-present, Facebook, Inc.
|
3 | *
|
4 | * This source code is licensed under the MIT license found in the
|
5 | * LICENSE file in the root directory of this source tree.
|
6 | *
|
7 | *
|
8 | */
|
9 |
|
10 | ;
|
11 |
|
12 | /**
|
13 | * @param {array} arr an "accumulation" of items which is either an Array or
|
14 | * a single item. Useful when paired with the `accumulate` module. This is a
|
15 | * simple utility that allows us to reason about a collection of items, but
|
16 | * handling the case when there is exactly one item (and we do not need to
|
17 | * allocate an array).
|
18 | */
|
19 |
|
20 | function forEachAccumulated(arr, cb, scope) {
|
21 | if (Array.isArray(arr)) {
|
22 | arr.forEach(cb, scope);
|
23 | } else if (arr) {
|
24 | cb.call(scope, arr);
|
25 | }
|
26 | }
|
27 |
|
28 | module.exports = forEachAccumulated; |
\ | No newline at end of file |