Litote / kmongo

[deprecated] KMongo - a Kotlin toolkit for Mongo
https://litote.org/kmongo/
Apache License 2.0
781 stars 75 forks source link

Behavior of `evaluate` when no results are available #384

Open CLOVIS-AI opened 1 year ago

CLOVIS-AI commented 1 year ago

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?

zigzago commented 1 year ago

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

CLOVIS-AI commented 1 year ago

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

zigzago commented 1 year ago

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

CLOVIS-AI commented 1 year ago

“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.