@rxjs-ninja/rxjs-array
Version:
Operators for RxJS for filtering with boolean logic
37 lines (36 loc) • 1.28 kB
TypeScript
/**
* @packageDocumentation
* @module Array
*/
import { OperatorFunction } from 'rxjs';
import { PredicateFn } from '../types/generic-methods';
/**
* Returns an Observable number which is the index of the first value found in an array using Array.findIndex
* 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 Query
*
* @typeParam T Item type contained in the Array or Set
*
* @param predicate Optional [[PredicateFn]] used to get a truthy or falsy value of array values
*
* @example
* Returns the index of the first value that is `> 2`
* ```ts
* const input = [1, 2, 3, 4, 5]
* of(input).pipe(findIndex(v => v > 2)).subscribe();
* ```
* Output: `2`
*
* @example
* Returns the index of the first string where the length `< 5`
* ```ts
* const input = ['Hello', 'RxJS', 'Ninja'];
* of(input).pipe(findIndex(v => v.length < 5)).subscribe();
* ```
* Output: `1`
*
* @returns An Observable that emits a number value, the index of first value where [[PredicateFn]] is true
*/
export declare function findIndex<T extends unknown>(predicate?: PredicateFn<T>): OperatorFunction<Iterable<T>, number>;