[RxJS] Transformation operator: map and mapTo
We made our first operator called multiplyBy, which looks a bit useful, but in practice we don't need it because it's too specific: it only does simple multiplication on numbers. In this lesson we will see how the map() operator is useful for any calculation on delivered values.
map:
var foo = Rx.Observable.interval(1000); /* foo: ---0---1---2---3--...
map(x => x / 2)
bar: ---0---2---4---6--... */ // map take a function
var bar = foo.map(x => x / 2); bar.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);
mapTo:
var foo = Rx.Observable.interval(1000); /* foo: --- 0---1--- 2--- 3--...
mapTo(10)
bar: ---10---10---10---10--... */ // mapTo take a value
var bar = foo.mapTo(10); bar.subscribe(
function (x) { console.log('next ' + x); },
function (err) { console.log('error ' + err); },
function () { console.log('done'); },
);
[RxJS] Transformation operator: map and mapTo的更多相关文章
- [RxJS] Transformation operator: repeat
Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...
- [RxJS] Transformation operator: scan
All of the combination operators take two or more observables as input. These operators may also be ...
- [RxJS] Transformation operator: buffer, bufferCount, bufferTime
This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...
- [RxJS] Transformation operator: bufferToggle, bufferWhen
bufferToggle(open: Observable, () => close: Observalbe : Observalbe<T[]>) bufferToggle take ...
- [RxJS] Utility operator: do
We just saw map which is a transformation operator. There are a couple of categories of operators, s ...
- rxjs自定义operator
rxjs自定义operator
- [RxJS] Implement the `map` Operator from Scratch in RxJS
While it's great to use the RxJS built-in operators, it's also important to realize you now have the ...
- [RxJS] Use RxJS concatMap to map and concat high order observables
Like switchMap and mergeMap, concatMap is a shortcut for map() followed by a concatAll(). In this le ...
- [RxJS] Combination operator: withLatestFrom
Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLate ...
随机推荐
- wordpress4.0.1源码学习和摘录--函数
1.根据类型获取当前时间 function current_time( $type, $gmt = 0 ) { switch ( $type ) { case 'mysql': return ( $g ...
- Meditation Guide
Meditation “Stop!!!” don’t we just scream[vi. 尖叫:呼啸:发出尖锐刺耳的声音:令人触目惊心 ] this in our minds when the da ...
- 知识管理(knowledge Management)2
①找到生命的主轴 ②跨领域知识管理
- AVR GCC对端口的操作指南
1. AVR GCC for AVR I.I/O端口API1. BV用法:BV(pos);说明:将位定义转换成屏蔽码(MASK).与头文件io.h里的位定义一起使用.例如,置位WDTOE和WDE可表示 ...
- UFLDL教程之(一)sparseae_exercise
下面,将UFLDL教程中的sparseae_exercise练习中的各函数及注释列举如下 首先,给出各函数的调用关系 主函数:train.m (1)调用sampleIMAGES函数从已知图像中扣取多个 ...
- [BZOJ 1106] [POI2007] 立方体大作战tet 【树状数组】
题目链接:BZOJ - 1106 题目分析 从1到2n枚举每一个位置. 如果枚举到某一个数,这个数已经是第二次出现,那么就看它和第一次出现的位置之间有多少数还没有被匹配,有多少没有匹配的就要进行多少次 ...
- windows下NGINX和PHP配合(FASTCGI)
昨天测试了TOMCAT,今天考查了NGINX. 按网上说的作,比较简单. http://www.cnblogs.com/huayangmeng/archive/2011/06/15/2081337.h ...
- MySQL FEDERATED引擎使用示例, 类似Oracle DBLINK
原文地址:http://it.dataguru.cn/article-3352-1.html 摘要: 本地MySQL数据库要访问远程MySQL数据库的表中的数据, 必须通过FEDERATED存储引擎来 ...
- AlarmManager.setRepeating将不再准确
背景: 当我们想让Android应用程序定时为做一件工作时,我们往往会在一个BroadcastReceiver中使用AlarmManager.setRepeating()方法来实现.在API 19(即 ...
- Unity Twist Effect Black Hole
Shader "Hidden/Twist Effect" {Properties { _MainTex ("Base (RGB)", 2D) = "w ...