0

I have a question about the pipes of the observables

suppose I have the following code:

const skip$ = of(4);
const length$ = of(24);
const schoolId$ = of(1);

const source = combineLatest(skip$, length$, schoolId$).pipe(
  map(([skip, length]) => `skip: ${skip}, length: ${length}`),
  map(text => text ) // I need now schoolId, how can i get
);

in the second map i need the schoolId. How can i get the schoolId without doing this:

const source = combineLatest(skip$, length$, schoolId$).pipe(
  map(([skip, length, schoolId]) => ({text: `skip: ${skip}, length: ${length}`, schoolId})),
  map(text => `${text.text}, schoolId: ${text.schoolId}` )
);

here you have the stackblitz to try

1 Answers1

3

As with all things ReactiveX, you've got a lot of options. Maybe the closest to what you've got now would be to use withLatestFrom...

const source = combineLatest(skip$, length$).pipe(
  map(([skip, length]) => (`skip: ${skip}, length: ${length}`)),
  withLatestFrom(schoolId$),
  map(([text, schoolId]) => `${text}, schoolId: ${schoolId}` )
);
Adam Dunkerley
  • 664
  • 6
  • 14