UNPKG

@rxjs-ninja/rxjs-array

Version:

Operators for RxJS for filtering with boolean logic

47 lines (46 loc) 1.82 kB
/** * @packageDocumentation * @module Array */ import { OperatorFunction, Subscribable } from 'rxjs'; /** * Returns an Observable array of values filled with Array.fill. Using the source array length, some or all the values * are replaced with the `fillWith` parameter. * * @category Modify * * @param fillWith The value to fill the array with * @param startIndex Optional start index to fill the array from * @param endIndex Optional index of the item to stop filling at, the last item filled is `fillTo - 1` * * @typeParam T Item type contained in the input Array or Set * @typeParam K Item type container in the output Array or Set * * @example * Return an array with all values replaced * ```ts * const input = ['The', 'Cake', 'is', 'a', 'lie']; * of(input).pipe(fill('CAKE!')).subscribe(); * ``` * Output: `'CAKE!', 'CAKE!', 'CAKE!', 'CAKE!', 'CAKE!'` * * @example * Return an array where all items at and after index `2` are replaced * ```ts * const input = ['The', 'Cake', 'is', 'a', 'lie']; * of(input).pipe(fill('CAKE!', 2)).subscribe(); * ``` * Output: `'The', 'Cake', 'CAKE!', 'CAKE!', 'CAKE!'` * * @example * Return an array where all items at index `2` and upto index `4` are replaced * ```ts * const input = ['The', 'Cake', 'is', 'a', 'lie']; * of(input).pipe(fill('CAKE!', 2, 4)).subscribe(); * ``` * Output: `'The', 'Cake', 'CAKE!', 'CAKE!', 'lie'` * * @returns An Observable that emits an Array of values where some or all of the source array values are replaced with * the `fillValue` */ export declare function fill<T extends unknown, K extends unknown>(fillWith: Subscribable<K> | K, startIndex?: Subscribable<number> | number, endIndex?: Subscribable<number> | number): OperatorFunction<Iterable<T>, K[]>;