UNPKG

@arrows/array

Version:
42 lines (41 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.slice = void 0; const curry_1 = require("@arrows/composition/curry"); const _sliceFrom = (from, arr) => arr.slice(from); const _sliceTo = (to, arr) => arr.slice(0, to); const _slice = (from, to, arr) => arr.slice(from, to); const curriedSlice = curry_1.default(_slice); /** * Functional wrapper for Array.prototype.slice * * Creates a new array as a a section of an initial array. * * @param from The beginning of the specified portion of the array. * @param to The end of the specified portion of the array. * @param arr Initial array * @returns New array * * @method from Version with implicit end index (arr.length) * @method to Version with implicit start index (0) */ const slice = Object.assign(curriedSlice, { /** * Version with implicit end index (arr.length). * * @param from The beginning of the specified portion of the array. * @param arr Initial array * @returns New array */ from: curry_1.default(_sliceFrom), /** * Version with implicit start index (0). * * @param to The end of the specified portion of the array. * @param arr Initial array * @returns New array */ to: curry_1.default(_sliceTo), }); exports.slice = slice; exports.default = slice;