-1

Here i my sample code which returns list of JsonDocument from couchbase server.

Cluster cluster = CouchbaseCluster.create();
Bucket bucket = cluster.openBucket();

List<JsonDocument> foundDocs = Observable
    .just("key1", "key2", "key3", "key4", "key5")
    .flatMap(new Func1<String, Observable<JsonDocument>>() {
        @Override
        public Observable<JsonDocument> call(String id) {
            return bucket.async().get(id);
        }
    })
    .toList()
    .toBlocking()
    .single();

I want to return Map instead of List.My return type would be Map<String, JsonDocument>. I tried with toMap method but it did not work for me.

Nitin
  • 2,701
  • 2
  • 30
  • 60

1 Answers1

0

You correctly mentioned in your comment that toMap needs a Function as its argument. This Function will be used to "extract" (or maybe "construct") the key under which each value will be entered into the map.

So, in your case you will need a Function<JsonDocument, String> that takes a JsonDocument as its input and somehow returns a String which you will later use to find the JsonDocument in the Map. What that String will be is something only you can answer - maybe there is some ID inside the JsonDocument?

david.mihola
  • 12,062
  • 8
  • 49
  • 73