UNPKG

@arrows/array

Version:
56 lines (55 loc) 2.19 kB
declare type CurryFill1<T, V> = (arr: T[]) => (T | V)[]; declare type CurryFill2<T, V> = { (value: V): CurryFill1<T, V>; (value: V, arr: (T | V)[]): (T | V)[]; }; declare type CurryFill3<T, V> = { (endIndex: number | undefined): CurryFill2<T, V>; (endIndex: number | undefined, value: V): CurryFill1<T, V>; (endIndex: number | undefined, value: V, arr: (T | V)[]): (T | V)[]; }; declare type CurryFill4 = { <T, V>(startIndex: number | undefined): CurryFill3<T, V>; <T, V>(startIndex: number | undefined, endIndex: number | undefined): CurryFill2<T, V>; <T, V>(startIndex: number | undefined, endIndex: number | undefined, value: V): CurryFill1<T, V>; }; declare type _Fill = <T, V>(startIndex: number | undefined, endIndex: number | undefined, value: V, arr: (T | V)[]) => (T | V)[]; declare type CurriedFill = _Fill & CurryFill4; declare type FillAll = { <T, V>(value: V, arr: T[]): V[]; <T, V>(value: V): (arr: T[]) => V[]; }; declare type FillEnd = { <T, V>(endIndex: number, value: V, arr: (T | V)[]): (T | V)[]; <T, V>(endIndex: number, value: V): CurryFill1<T, V>; <T, V>(endIndex: number): CurryFill2<T, V>; }; declare type CurriedFillStart = { <T, V>(startIndex: number, value: V): CurryFill1<T, V>; <T, V>(startIndex: number): CurryFill2<T, V>; }; declare type _FillStart = <T, V>(startIndex: number, value: V, arr: (T | V)[]) => (T | V)[]; declare type FillStart = _FillStart & CurriedFillStart; declare type Fill = CurriedFill & { all: FillAll; end: FillEnd; start: FillStart; }; /** * Creates a new array with section identified by start and end index * filled with provided value. * Have built-in methods for common cases. * * @param startIndex Start index (if undefined - fill from start) * @param endIndex End index (if undefined - fill to the end) * @param value Value with which selected section will be filled. * @param arr Initial array * @returns New array * * @method all Fill from the start to the end * @method end Fill from the specified index to the end * @method start Fill from the specified index to the end */ declare const fill: Fill; export { fill }; export default fill;