2015-06-04 17:27:51 +00:00
|
|
|
/**
|
2016-05-26 19:22:30 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-06-04 17:27:51 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2018-06-20 07:35:29 +00:00
|
|
|
* @flow strict
|
2015-06-04 17:27:51 +00:00
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2015-06-04 17:27:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-05-26 19:22:30 +00:00
|
|
|
function mapWithSeparator<TFrom, TTo>(
|
|
|
|
items: Array<TFrom>,
|
|
|
|
itemRenderer: (item: TFrom, index: number, items: Array<TFrom>) => TTo,
|
|
|
|
spacerRenderer: (index: number) => TTo,
|
|
|
|
): Array<TTo> {
|
|
|
|
const mapped = [];
|
|
|
|
if (items.length > 0) {
|
|
|
|
mapped.push(itemRenderer(items[0], 0, items));
|
|
|
|
for (let ii = 1; ii < items.length; ii++) {
|
|
|
|
mapped.push(spacerRenderer(ii - 1), itemRenderer(items[ii], ii, items));
|
2015-06-04 17:27:51 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-26 19:22:30 +00:00
|
|
|
return mapped;
|
2015-06-04 17:27:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = mapWithSeparator;
|