Skip to content

Commit b5cc5fb

Browse files
FlatMap document result
1 parent 3b23efb commit b5cc5fb

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

driver/src/main/scala/org/reactivecouchbase/client/Queries.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class QueryEnumerator[T](futureEnumerator: () => Future[Enumerator[T]]) {
6969
def toEnumerator: Future[Enumerator[T]] = futureEnumerator()
7070

7171
/**
72-
*
72+
*
7373
* @param ec ExecutionContext for async processing
7474
* @return the query result as enumerator
7575
*/
@@ -86,7 +86,7 @@ class QueryEnumerator[T](futureEnumerator: () => Future[Enumerator[T]]) {
8686
futureEnumerator().flatMap(_(Iteratee.getChunks[T]).flatMap(_.run))
8787

8888
/**
89-
*
89+
*
9090
* @param ec ExecutionContext for async processing
9191
* @return the optinal head
9292
*/
@@ -222,10 +222,12 @@ trait Queries {
222222
QueryEnumerator(() => rawSearch(view)(query)(bucket, ec).toEnumerator.map { enumerator =>
223223
enumerator &>
224224
Enumeratee.map[RawRow] { row =>
225-
row.document.map { doc =>
226-
if (doc != null)
227-
JsRow[T](r.reads(Json.parse(doc)), row.id, row.key, row.value)
228-
else null
225+
row.document.flatMap { doc =>
226+
if (doc != null) {
227+
Some(JsRow[T](r.reads(Json.parse(doc)), row.id, row.key, row.value))
228+
} else {
229+
None
230+
}
229231
}.getOrElse(
230232
JsRow[T](JsError(), row.id, row.key, row.value)
231233
)

0 commit comments

Comments
 (0)