@rxjs-ninja/rxjs-array
Version:
Operators for RxJS for filtering with boolean logic
35 lines (34 loc) • 1.2 kB
TypeScript
/**
* @packageDocumentation
* @module Array
*/
import { OperatorFunction } from 'rxjs';
import { PredicateFn } from '../types/generic-methods';
/**
* Returns an Observable array of truthy values from a source Array or Set
* 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
*
* @param predicate Optional [[PredicateFn]] used to get a truthy value of array values
*
* @example
* Return an array of all numbers that are truthy
* ```ts
* const input = [0, 10, 1, 0, 6, 6, 0, 1];
* of(input).pipe(findAll()).subscribe();
* ```
* Output: `[10, 1, 6, 6, 1]`
*
* @example
* Return an array of values where the source array value length `>= 5`
* ```ts
* const input = ['', '', 'Hello', 'RxJS', 'Ninja'];
* of(input).pipe(findAll(v => v.length >= 5)).subscribe();
* ```
* Output: `['Hello', 'Ninja']`
*
* @returns An Observable that emits an array containing all truthy values from a source array
*/
export declare function findAll<T extends unknown>(predicate?: PredicateFn<T>): OperatorFunction<Iterable<T>, T[]>;