import { from, of } from 'rxjs';
import { filter, first, last, single, skip, skipWhile,
distinct,take, takeLast } from 'rxjs/operators';
const source = from([1, 2, 3, 4, 5]);
const source$ = of(1, 2, 3, 4, 5);
//filter out non-even numbers
let example = source.pipe(filter(num => num % 2 === 0));
//output: "Even number: 2", "Even number: 4"
//no arguments, emit first value
example = source.pipe(first());
//output: "First value: 1"
example = source.pipe(last());
//output: "Last value: 5"
//emit one item that matches predicate
example = source.pipe(single(val => val === 4));
//output: 4
//skip the first 2 emitted values
example = source.pipe(skip(2));
//output: 3...4...5...
//skip emitted values from source until inner observable emits (6s)
example = source.pipe(skipWhile(a => a < 3));
//output: 3...4...5
of(1, 2, 3, 4, 5, 1, 2, 3, 4, 5).pipe(distinct()).subscribe(console.log);
// OUTPUT: 1,2,3,4,5
//take the first emitted value then complete
example = source$.pipe(take(1));
//output: 1
// take the last 2 emitted values
example = source$.pipe(takeLast(2));
//output: 4,5