signature: filter(select: Function, thisArg: any): Observable
// RxJS v6+
import { from } from 'rxjs';
import { filter } from 'rxjs/operators';
//(1,2,3,4,5)를 발생시킵니다
const source = from([1, 2, 3, 4, 5]);
//짝수가 아닌 수들을 걸러냅니다
const example = source.pipe(filter(num => num % 2 === 0));
//결과: "Even number: 2", "Even number: 4"
const subscribe = example.subscribe(val => console.log(`Even number: ${val}`));
// RxJS v6+
import { from } from 'rxjs';
import { filter } from 'rxjs/operators';
//({name: 'Joe', age: 31}, {name: 'Bob', age:25}) 을 발생시킵니다
const source = from([{ name: 'Joe', age: 31 }, { name: 'Bob', age: 25 }]);
//age가 30 미만인 사람들을 걸러냅니다
const example = source.pipe(filter(person => person.age >= 30));
//결과: "Over 30: Joe"
const subscribe = example.subscribe(val => console.log(`Over 30: ${val.name}`));
// RxJS v6+
import { interval } from 'rxjs';
import { filter } from 'rxjs/operators';
//매 1초마다 값을 발생시킵니다
const source = interval(1000);
//interval로 발생시키는 값이 5보다 클 때까지, 모든 값들을 걸러냅니다
const example = source.pipe(filter(num => num > 5));
/*
"Number greater than 5: 6"
"Number greater than 5: 7"
"Number greater than 5: 8"
"Number greater than 5: 9"
*/
const subscribe = example.subscribe(val =>
console.log(`Number greater than 5: ${val}`)
);