Skip to content

Instantly share code, notes, and snippets.

@daschl
Last active June 2, 2016 14:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daschl/11252782 to your computer and use it in GitHub Desktop.
Save daschl/11252782 to your computer and use it in GitHub Desktop.
Official Couchbase Java SDK Preview - Document Loading
// Load 3 Documents and process them one after another
// Java 8:
Observable
.from("doc1", "doc2", "doc3")
.flatMap(id -> bucket.get(id))
.subscribe(doc -> System.out.println(doc));
// Java 6 & 7
Observable
.from("doc1", "doc2", "doc3")
.flatMap(new Func1<String, Observable<Document>>() {
@Override
public Observable<Document> call(String id) {
return bucket.get(id);
}
})
.subscribe(new Action1<Document>() {
@Override
public void call(Document doc) {
System.out.println(doc);
}
});
// Load 3 Documents and process them together
// Java 8:
Observable
.from("doc1", "doc2", "doc3")
.flatMap(id -> bucket.get(id))
.toList()
.subscribe(docs -> System.out.println(docs));
// Java 6 & 7
Observable
.from("doc1", "doc2", "doc3")
.flatMap(new Func1<String, Observable<Document>>() {
@Override
public Observable<Document> call(String id) {
return bucket.get(id);
}
})
.toList()
.subscribe(new Action1<List<Document>>() {
@Override
public void call(List<Document> docs) {
System.out.println(docs)
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment