Is it possible to work with a stream of arrays, such as filtering, and then emit the arrays again without concatenating the elements of the arrays or using regular array operators? For example, if I have an observable containing a single array, I can perform the following actions:
const MINWEIGHT = 15;
interface fruit {
name: string;
weight: number;
}
let apple: fruit = { name: "apple", weight: 2 };
let orange: fruit = { name: "orange", weight: 20 };
let fruitBasket1 = [apple, orange, orange];
let fruitBasket2 = [apple, apple, apple];
let sub = new Subject<fruit[]>();
sub
.asObservable()
.pipe(
concatMap(x => x),
filter(x => x.weight > MINWEIGHT),
toArray()
)
.subscribe(console.log); // result: [ orange, orange];
sub.next(fruitBasket1);
sub.complete();
If sub.complete()
is not called and there are multiple emissions of fruit[] (e.g. fruitBasket2)
, can the observable emit two arrays ([orange, orange], [orange])
without using regular array operators? While it's easily achievable with map (RxJS) followed by filter (array operator), I am interested in knowing if it can be done solely using RxJS operators.