@rxjs-ninja/rxjs-array
Version:
Operators for RxJS for filtering with boolean logic
47 lines (46 loc) • 1.79 kB
TypeScript
/**
* @packageDocumentation
* @module Array
*/
import { PredicateFn } from '../types/generic-methods';
import { OperatorFunction } from 'rxjs';
/**
* Returns an Observable that emits an array when all values in the source array return truthy using Array.every.
* When working with data, if the array contains numbers `0` will be returned as a value to the [[PredicateFn]], but all
* other falsy values will be ignored
*
* @category Filter
*
* @see The [[every]] operator returns the boolean value instead of the array
*
* @typeParam T Item type contained in the Array or Set
*
* @param predicate Optional [[PredicateFn]] used to get a truthy value of array values
*
* @example
* Returns a array where every string item in the array is truthy
* ```ts
* const input = [ ['', '', ''], ['', 'Hello', 'RxJS'], ['Hello', 'RxJS', 'Ninja'] ];
* from(input).pipe(filterEvery()).subscribe();
* ```
* Output: `['Hello', 'RxJS', 'Ninja']`
*
* @example
* Returns a array where every string item in the array length `< 4`
* ```ts
* const input = [ ['', '', ''], ['', 'Foo', 'Bar'], ['Foo', 'Bar', 'Baz'] ];
* from(input).pipe(filterEvery(v => v.length < 4)).subscribe();
* ```
* Output: `['Foo', 'Bar', 'Baz']`
*
* @example
* Returns a array where every number in the array is less than `2`
* ```ts
* const input = [ [1, 0, 1, 0, 1, 0], [1, 0, 2, 1, 0, 2], [0, 1, 0, 1, 0, 2] ];
* from(input).pipe(filterEvery(v => v < 2)).subscribe();
* ```
* Output: `[1, 0, 1, 0, 1, 0]`
*
* @returns An Observable that emits a boolean when all values in source array return truthy with the [[PredicateFn]]
*/
export declare function filterEvery<T extends unknown>(predicate?: PredicateFn<T>): OperatorFunction<Iterable<T>, T[]>;