kmongo icon indicating copy to clipboard operation
kmongo copied to clipboard

Behavior of `evaluate` when no results are available

Open CLOVIS-AI opened this issue 3 years ago • 4 comments
trafficstars

What does evaluate do when no results are found?

Ideally, I'd like it to call the lambda with an empty sequence:

myCollection.find(…).evaluate {
    println(isEmpty()) // prints 'true'
}

In case this is the current behavior, would it be possible to add a sentence to make it clear in evaluate's documentation?

CLOVIS-AI avatar Nov 17 '22 15:11 CLOVIS-AI

Kotlin sequences (https://kotlinlang.org/docs/sequences.html) do not have isEmpty() method but you can write

col.find().evaluate {
            println(count() == 0) // prints 'true'
        }

HTH

zigzago avatar Nov 27 '22 19:11 zigzago

Is it possible to make it clear in evaluate's documentation?

CLOVIS-AI avatar Nov 27 '22 20:11 CLOVIS-AI

What would you like to add to the current doc? https://litote.org/kmongo/dokka/kmongo/org.litote.kmongo/com.mongodb.client.-mongo-iterable/evaluate.html

zigzago avatar Nov 27 '22 20:11 zigzago

“Evaluates the current MongoIterable given the expression of Sequences, including when it is empty.” or similar.

At least this way it's clear that it's an intended behavior and it won't go away in the future.

CLOVIS-AI avatar Nov 27 '22 20:11 CLOVIS-AI