From 9461df16f71186ea40b365622900b03d7f7bb387 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Fri, 22 Oct 2021 00:07:42 +0300 Subject: [PATCH] add filterEach operator --- src/lib/utils/operators.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/utils/operators.ts b/src/lib/utils/operators.ts index c7580e9..a8de46e 100644 --- a/src/lib/utils/operators.ts +++ b/src/lib/utils/operators.ts @@ -1,17 +1,21 @@ import { distinctUntilChanged, map } from 'rxjs/operators'; import { OperatorFunction, pipe } from 'rxjs'; -export function get(predicate: (value: T, index: number) => boolean): OperatorFunction { +export function get(predicate: (value: T, index: number) => boolean): OperatorFunction { return map(entities => entities.find(predicate)); } -export function any(predicate: (value: T, index: number) => boolean): OperatorFunction { +export function any(predicate: (value: T, index: number) => boolean): OperatorFunction { return map(entities => entities.some(predicate)); } -export function mapEach(predicate: (value: T, index: number) => R): OperatorFunction { +export function mapEach(predicate: (value: T, index: number) => R): OperatorFunction { return map(entities => entities.map(predicate)); } +export function filterEach(predicate: (value: T, index: number) => boolean): OperatorFunction { + return map(entities => entities.filter(predicate)); +} + export const toLengthValue = (entities: unknown[]): number => entities?.length ?? 0; export const getLength = pipe(map(toLengthValue), distinctUntilChanged());