Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
How to apply filter to pairwise?

I have the stream:

 this.unselectedObjectsIds$ = this.selectedObjectsIds$.pipe(pairwise());

Where this.selectedObjectsIds$ is

[
   ['131086', '131089', '131090', '131638', '132139'], 
   ['131086', '131089']
]

I try to apply this fiilter to the stream:

this.unselectedObjectsIds$ = this.selectedObjectsIds$.pipe(
    pairwise(), 
    map((a) => a[0].filter(x => !a[1].includes(x))
);

Filter is:

a[0].filter(x => !a[1].includes(x));

But it does not work for me.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

pairwise is waiting for the next value

Because you have only one value - it is array: [['131086', '131089', '131090', '131638', '132139'], ['131086', '131089']]

if selectedObjectsIds$ is BehaviorSubject for example

you need send a new value selectedObjectsIds$.next([]) and your code will be paired as

[[['131086', '131089', '131090', '131638', '132139'], ['131086', '131089']], []]

I will try to guess what you are going to have in OUTPUT:

is it ["131090", "131638", "132139"]?

if yes - then use next snippet

import { map, pairwise, take, tap } from 'rxjs/operators';
import { BehaviorSubject, interval, of } from 'rxjs';

const selectedObjectsIds$ = new BehaviorSubject([
  ['131086', '131089', '131090', '131638', '132139'],
  ['131086', '131089'],
]);

const unselectedObjectsIds$ = selectedObjectsIds$.pipe(
  tap((data) => {
    console.log(data);
  }),
  map(([arr1, arr2]) => {
    console.log(arr1);
    console.log(arr2);
    return arr1.filter((x) => !arr2.find((i) => i === x));
  })
);
unselectedObjectsIds$.subscribe((data) => console.log(data));


demo: https://stackblitz.com/edit/typescript-i4nazm?file=index.ts

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda