22 lines
963 B
TypeScript
22 lines
963 B
TypeScript
import { distinctUntilChanged, map } from 'rxjs/operators';
|
|
import { OperatorFunction, pipe } from 'rxjs';
|
|
|
|
export function get<T>(predicate: (value: T, index: number) => boolean): OperatorFunction<readonly T[], T | undefined> {
|
|
return map(entities => entities.find(predicate));
|
|
}
|
|
|
|
export function any<T>(predicate: (value: T, index: number) => boolean): OperatorFunction<readonly T[], boolean> {
|
|
return map(entities => entities.some(predicate));
|
|
}
|
|
|
|
export function mapEach<T, R>(predicate: (value: T, index: number) => R): OperatorFunction<readonly T[], R[]> {
|
|
return map(entities => entities.map(predicate));
|
|
}
|
|
|
|
export function filterEach<T>(predicate: (value: T, index: number) => boolean): OperatorFunction<readonly T[], T[]> {
|
|
return map(entities => entities.filter(predicate));
|
|
}
|
|
|
|
export const toLengthValue = (entities: unknown[]): number => entities?.length ?? 0;
|
|
export const getLength = pipe(map(toLengthValue), distinctUntilChanged());
|