add filterEach operator
This commit is contained in:
parent
df3a8957c8
commit
9461df16f7
@ -1,17 +1,21 @@
|
||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||
import { OperatorFunction, pipe } from 'rxjs';
|
||||
|
||||
export function get<T>(predicate: (value: T, index: number) => boolean): OperatorFunction<T[], T | undefined> {
|
||||
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<T[], boolean> {
|
||||
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<T[], R[]> {
|
||||
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());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user