Medium
You're implementing a simple Observable pattern with operators. What's the correct implementation of the pipe method?
1class Observable {2 constructor(subscriber) {3 this.subscriber = subscriber;4 }56 subscribe(observer) {7 return this.subscriber(observer);8 }910 // Missing implementation11 pipe(...operators) {12 ____________________13 ____________________14 ____________________15 ____________________16 }17}1819// Example operators20const map = (fn) => (source) =>21 new Observable(observer =>22 source.subscribe({23 next: (value) => observer.next(fn(value)),24 error: (err) => observer.error(err),25 complete: () => observer.complete()26 })27 );2829const filter = (predicate) => (source) =>30 new Observable(observer =>31 source.subscribe({32 next: (value) => predicate(value) && observer.next(value),33 error: (err) => observer.error(err),34 complete: () => observer.complete()35 })36 );3738// Usage:39const source$ = new Observable(observer => {40 observer.next(1);41 observer.next(2);42 observer.next(3);43 observer.complete();44});4546const result$ = source$.pipe(47 filter(x => x > 1),48 map(x => x * 10)49);