Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 565 Bytes

File metadata and controls

26 lines (21 loc) · 565 Bytes

filter

L'opérateur filter permet de ne garder que les éléments pour lesquels la fonction predicate retourne true.

import { from } from 'rxjs';
import { filter } from 'rxjs/operators';const getTemperature = city => 100 / city.length;/* Create an Observable from an array : Strasbourg => Nice => Lyon. */
const city$ = from(['Strasbourg', 'Nice', 'Lyon']);const hotCity$ = city$
    .pipe(filter(city => getTemperature(city) > 20));hotCity$.subscribe(city => console.log(city));

Résultat :

Nice
Lyon