add bool factory

This commit is contained in:
Dan Percic 2022-02-02 13:56:06 +02:00
parent 918326d4fe
commit b662479794

View File

@ -27,3 +27,12 @@ export function shareDistinctLast<T>(values = 1): UnaryFunction<Observable<T>, O
export const toLengthValue = (entities: unknown[]): number => entities?.length ?? 0;
export const getLength = pipe(map(toLengthValue), distinctUntilChanged());
export function boolFactory<T>(obs: Observable<T>, project: (value: T) => boolean): Observable<boolean>[] {
const result = obs.pipe(map(project), shareDistinctLast());
const inverse = result.pipe(
map(value => !value),
shareDistinctLast(),
);
return [result, inverse];
}