1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports["default"] = void 0;
|
---|
5 | var _ramda = require("ramda");
|
---|
6 | /**
|
---|
7 | * Returns a new list with the item at the position `fromIdx` moved to the position `toIdx`. If the
|
---|
8 | * `toIdx` is out of the `list` range, the item will be placed at the last position of the `list`.
|
---|
9 | * When negative indices are provided, the behavior of the move is unspecified.
|
---|
10 | *
|
---|
11 | * @func move
|
---|
12 | * @memberOf RA
|
---|
13 | * @since {@link https://char0n.github.io/ramda-adjunct/2.8.0|v2.8.0}
|
---|
14 | * @category List
|
---|
15 | * @sig Number -> Number -> [a] -> [a]
|
---|
16 | * @param {number} fromIdx The position of item to be moved
|
---|
17 | * @param {number} toIdx The position of item after move
|
---|
18 | * @param {Array} list The list containing the item to be moved
|
---|
19 | * @return {Array}
|
---|
20 | * @example
|
---|
21 | *
|
---|
22 | * const list = ['a', 'b', 'c', 'd', 'e'];
|
---|
23 | * RA.move(1, 3, list) //=> ['a', 'c', 'd', 'b', 'e']
|
---|
24 | */
|
---|
25 | var move = (0, _ramda.curry)(function (fromIdx, toIdx, list) {
|
---|
26 | return (0, _ramda.compose)((0, _ramda.insert)(toIdx, (0, _ramda.nth)(fromIdx, list)), (0, _ramda.remove)(fromIdx, 1))(list);
|
---|
27 | });
|
---|
28 | var _default = move;
|
---|
29 | exports["default"] = _default; |
---|