2015-06-04 20:27:51 +03:00
|
|
|
/**
|
2019-03-28 23:44:57 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-05-26 22:22:30 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03: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 20:27:51 +03:00
|
|
|
*
|
2018-05-11 05:06:46 +03:00
|
|
|
* @format
|
2018-06-20 10:35:29 +03:00
|
|
|
* @flow strict
|
2015-06-04 20:27:51 +03:00
|
|
|
*/
|
2018-05-11 05:06:46 +03:00
|
|
|
|
2015-06-04 20:27:51 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-05-26 22:22:30 +03: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 20:27:51 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-26 22:22:30 +03:00
|
|
|
return mapped;
|
2015-06-04 20:27:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = mapWithSeparator;
|