[RxJS] Filtering operator: first
First Rxjs Operator Filtering
2023-09-14 08:59:13 时间
first(predFn, defVal)
first can do the work for both "filter" + "take(1)" which filtering the data and end observable.
// RxJS v6+ import { from } from 'rxjs'; import { first } from 'rxjs/operators'; const source = from([1, 2, 3, 4, 5]); //emit first item to pass test const example = source.pipe(first(num => num === 5)); //output: "First to pass test: 5" const subscribe = example.subscribe(val => console.log(`First to pass test: ${val}`) );
// RxJS v6+ import { from } from 'rxjs'; import { first } from 'rxjs/operators'; const source = from([1, 2, 3, 4, 5]); //no value will pass, emit default const example = source.pipe(first(val => val > 5, 'Nothing')); //output: 'Nothing' const subscribe = example.subscribe(val => console.log(val));
相关文章
- MySQL-- Entity Framework Code First(EF Code First)
- C#+EntityFramework编程方式详细之Code First 数据迁移
- 《Ext JS 4 First Look》翻译之三:布局
- [Functional Programming] mapReduce over Async operations with first success prediction (fromNode, alt, mapReduce, maybeToAsync)
- [RxJS 6] The Catch and Rethrow RxJs Error Handling Strategy and the finalize Operator
- [rxjs] Demystifying Cold and Hot Observables in RxJS
- [Backbone] First Application!!!!
- [RxJS] Filtering operator: first
- [RxJS 6] The Catch and Rethrow RxJs Error Handling Strategy and the finalize Operator
- Unexpected XML declaration. The XML declaration must be the first node in the document and no white
- Unexpected XML declaration. The XML declaration must be the first node in the document and no white
- [1] Entity Framework / Code First
- C# ORM—Entity Framework 之Database first(数据库优先)&Model First(模型优先)(一)
- 转载:News: Robot Framework 3.0 is the first Robot Framework version to support Python 3
- ! [rejected] master -> master (fetch first)解决办法