Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tusharmath's full-sized avatar
😑
Imploding

Tushar Mathur tusharmath

😑
Imploding
View GitHub Profile
@tusharmath
tusharmath / index.js
Created June 11, 2017 05:26 — forked from xgrommx/index.js
How we can make methods of observable via other methods
const flatMapLatest = (fn, stream) =>
stream.publish(s => s.flatMap(v => fn(v).takeUntil(s)));
const flatMapLatest = (fn, stream, resultSelector) => stream.publish(s => {
return s.flatMap(v => fn(v).map(v2 => resultSelector(v, v2)).takeUntil(s));
});
const delay = (source, delay) => source.flatMap(e => Rx.Observable.timer(delay).mapTo(e))
const debounceTime = (time, stream) => flatMapLatest(v => of(v).delay(time), stream);