Skip to content

Instantly share code, notes, and snippets.

@banujan6
Created September 5, 2021 08:59
Show Gist options
  • Save banujan6/307dfe06262ab5fa42ccbc98a7fa5916 to your computer and use it in GitHub Desktop.
Save banujan6/307dfe06262ab5fa42ccbc98a7fa5916 to your computer and use it in GitHub Desktop.
medium-rxjs-operators-pipeable
import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
// Create a Observable which emits 2 values
const observable = new Observable(subscriber => {
subscriber.next('First Message');
subscriber.next('Second Message');
});
// "first()" is a pipeable operator that only returns the observable with the first value.
observable
.pipe(first())
.subscribe(data => console.log(data));
// CONSOLE OUTPUT ------------------
// > First Message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment