davidchambers commented on issue #5582:
URL: https://github.com/apache/couchdb/issues/5582#issuecomment-3089184681
Thanks for your response, @rnewson. :)
It's a shame that special cases such as this will continue to be necessary:
```kotlin
// It should be acceptable to use {"creationEpoch": {"$and": []}} when
neither createdAfterInclusive
// nor createdBeforeExclusive is specified, but CouchDB does not understand
vacuous truth. 🙈
val creationSelector = listOfNotNull(
f.createdAfterInclusive?.let { mapOf("\$gte" to
it.toNanoEpoch().epoch.toString()) },
f.createdBeforeExclusive?.let { mapOf("\$lt" to
it.toNanoEpoch().epoch.toString()) },
).toNonEmptyListOrNull()?.let { mapOf("creationEpoch" to mapOf("\$and" to
it)) } ?: emptyMap()
```
I'd like to be able to write this instead:
```kotlin
val creationSelector = mapOf(
"creationEpoch" to mapOf(
"\$and" to listOfNotNull(
f.createdAfterInclusive?.let { mapOf("\$gte" to
it.toNanoEpoch().epoch.toString()) },
f.createdBeforeExclusive?.let { mapOf("\$lt" to
it.toNanoEpoch().epoch.toString()) },
),
),
)
```
> we are happy that `"$and": []` does not vacuously match everything
Could you elaborate? Are you concerned about backwards compatibility, or is
there some reason that CouchDB should behave differently from other programming
contexts?
Haskell:
```haskell
ghci> all even []
True
```
Python:
```python
>>> all(x % 2 == 0 for x in [])
True
```
JavaScript:
```javascript
> [].every(x => x % 2 === 0)
true
```
Clojure:
```clojure
user=> (every? even? [])
true
user=> (and)
true
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]