Difference between revisions of "Reactive functional programming"
From Wiki2
Line 2: | Line 2: | ||
internally: | internally: | ||
function map(fn) { | |||
var source=this | |||
result = Rx.Observable.create(function subscribe(observer){ | |||
source.subscribe( | |||
function(x) {observer.next(fn(x));}, | |||
function(err){ oberver.error(err));}, | |||
function() {observer.complete();} | |||
) | |||
}) | |||
} | |||
Rx.Observable.prototype.map = map | |||
Revision as of 08:43, 25 May 2016
rxjs
internally:
function map(fn) { var source=this result = Rx.Observable.create(function subscribe(observer){ source.subscribe( function(x) {observer.next(fn(x));}, function(err){ oberver.error(err));}, function() {observer.complete();} ) }) } Rx.Observable.prototype.map = map
operators
Rx.Observable.of(4,5,6,7,8) (45678|)
Rx.Observable.interval(500).take(4), a kind of filter, also: first, takeLast, last, skip, skipLast ---0---1---2---3|
[4,5,6,7].do(x=>console.log('dog is '+x)) //doesn't touch the Observable, passes it through
Rx.Observable.interval(500).take(4) ---0---1---2---3| foo (8,9,10,11|) more foo.concat(more) ---0---1---2---3(8,9,10,11|)