import { curryN } from "@unboxing/function"; import { isString } from "@unboxing/is"; interface Slice { (a: number, b: number, list: string): string; (a: number, b: number, list: ArrayLike): T[]; (a: number, b: number): { (list: string): string; (list: ArrayLike): T[]; }; (a: number): { (b: number, list: string): string; (b: number, list: ArrayLike): T[]; (b: number): { (list: string): string; (list: ArrayLike): T[]; }; }; } /** * Returns the elements of the given list or string (or object with a `slice` * method) from `fromIndex` (inclusive) to `toIndex` (exclusive). */ export const sliceArray = curryN(3, (fromIndex: number, toIndex: number, list: ArrayLike | string = []) => isString(list) ? list.slice(fromIndex, toIndex) : Array.prototype.slice.call(list, fromIndex, toIndex) ) as Slice