LiveLoveApp logo

Solution - Connect Operator

Solution

import { of } from "rxjs";
import { connect, filter, tap } from "rxjs/operators";

const source = of(1, 2, 3, 4, 5).pipe(
  tap((value) => console.log(`source: ${value}`))
);

/**
 * Use the `connect()` operator and specify the `selector` function.
 * Within the function provided, filter for even numbers only.
 */
source
  .pipe(
    connect((multicasted) =>
      multicasted.pipe(filter((value) => value % 2 === 0))
    )
  )
  .subscribe(console.log);