https://github.com/TechFreak/RxTalk
"The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods."
"Programming paradigm oriented around data flows and the propagation of change."
Ben Christensen from Netflix
Observable repos = githubApi.getRepos();
repos.subscribeOn(Schedulers.io()) <----- Multithreading
.observeOn(Schedulers.mainThread());
.subscribe( data-> showData(data) ); <----- Subscriber
Emit only the first item (or the first item that meets some condition) emitted by an Observable
Emit the emissions from two or more Observables without interleaving them
Only emit an item from an Observable if a particular timespan has passed without it emitting another item
Transform the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable
Observable searchTermChanged = ......;
searchTermChanged.debounce(2, TimeUnit.SECONDS)
.filter(onTextChangeEvent -> onTextChangeEvent.text().length() > 3)
.flatMap(onTextChangeEvent -> callSearchWebService(onTextChangeEvent.text())
.subscribe(searchResults -> showSearchResults(searchResults));
// Our sources
Observable memory = ...;
Observable disk = ...;
Observable network = ...;
// Save data into next cache as soon as
// it starts flowing
Observable network = network.doOnNext(data -> {
saveToDisk(data);
});
Observable disk = disk.doOnNext(data -> {
cacheInMemory(data);
});
// Retrieve the first source with data
Observable source = Observable
.concat(memory, disk, network)
.first(data -> data.isUpToDate()) <-- Only allow fresh data
.subscribe(data -> doSomething(data));