source: node_modules/ramda-adjunct/lib/move.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _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 */
25var 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});
28var _default = move;
29exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.